这是C#中的属性
public string UserName
{
get { return this._username; }
set { this._username = value; }
}
通俗来讲..get是获取值 set是设置值
比如这句:get { return this._username; }
如果调用这个get方法 就能获得方法return的 this._username(返回的值)
调用方法:Console.Write(对象.UserName);(输出该属性的值)
比如这句:set { this._username = value; }
如果调用这个set方法 就可以重新设置username的值 value就是你新设置的值
调用方法:对象.UserName="新值";(为该属性附新值)
C#中自定义属性,set与get用法
最新推荐文章于 2025-08-24 09:23:32 发布
本文详细介绍了C#中属性的概念及使用方法,包括get用于获取值,set用于设置值的具体实现方式,并提供了调用实例。

6794

被折叠的 条评论
为什么被折叠?



