public class Test
{
private string _testname;
public string testname
{
set { _testname = value; }
get { return _testname; }
}
public Test():this("test")
{ }
public Test(string test)
{
this.testname = test;
}
为什么要这样定义一个成员?定义两遍testname?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答
- 狂奔De鸵鸟 2020-01-14 17:33关注
private string _testname; 属于字段
public string testname
{
set { _testname = value; }
get { return _testname; }
} 属于属性这样定义是为了让外部只能通过属性来访问字段
字段是 private的
属性是public 的
当然你这个例子在编码规范上有点问题。
正确的编码规范是
字段首字母小写 应为他是一个变量
属性首字母要大写如有问题可以继续评论。
望采纳解决 无用评论 打赏 举报
悬赏问题
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 对于相关问题的求解与代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料
- ¥15 使用R语言marginaleffects包进行边际效应图绘制