读书人

这段代码啥意思?该怎么解决

发布时间: 2012-01-06 22:55:18 作者: rapoo

这段代码啥意思?

public static int FirstCatalogId
{
set
{
System.Web.HttpContext.Current.Session[ "_firstCatalogId "] = value;
}
get
{
if (System.Web.HttpContext.Current.Session[ "_firstCatalogId "] == null)
{
return 0;
}
else
{
return (int)System.Web.HttpContext.Current.Session[ "_firstCatalogId "];
}
}


value 是啥??没定义啊~~~谢谢~~

[解决办法]
这段代码是一个类的属性

Value是一个int值
[解决办法]
不需要定义的,这是属性的标准写法

使用的时候

设置:
类名.FirstCatalogId=100;

获得:
int a=类名.FirstCatalogId;

[解决办法]
属性的写法:
public int aa
{
get { return m_aa; }
set { aa= value ; }
}
如:Class c_BB = new c_BB;
c_BB.aa = 45;(这个45就是你所说的保留字value--接受的外界赋值),属性的一个用途就是为了隐藏私有成员(比如此处的m_aa)用的。

读书人网 >C#

热点推荐