2012-08-13 15:40来源:武汉北大青鸟鲁广校区作者:027hpit
武汉北大青鸟武汉宏鹏鲁广校区在学习过程中领悟到,觉得.NET 的那个叫“属性”的东东应该叫属性访问器比较好。特别对那些同时学Java 和.NET 的ACCP初学者来说是一种混淆,在Java 中叫属性的东东在.NET 中叫字段是不是特别扭,有木有?
.net
namespace Admin.Model
{
public class UserGroup
{
//字段
protected int _id;
protected string _userGroupName;
protected string _description;
//无参构造函数
public UserGroup() { }
//带参数的构造函数
public UserGroup(string userGroupName, string description)
{
this._userGroupName = userGroupName;
this._description = description;
}
//Id属性访问器
public int Id
{
get { return _id; }
set { _id = value; }
}
//UserGroupName属性访问器
public string UserGroupName
{
get { return _userGroupName; }
set
{
if (value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("Invalid value for UserGroupName", value, value.ToString());
_userGroupName = value;
}
}
//Description属性访问器
public string Description
{
get { return _description; }
set
{
if (value != null && value.Length > 8000)
throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
_description = value;
}
}
}
}
大家看明白了吗?这位同学说的对不对呢?想了解更多关于.net技术的交流请继续关注武汉北大青鸟官方网站。
Copyright (c) 2006-2020 武汉宏鹏职业培训学校 版权所有 All Rights Reserved.