C# 是得到;设置属性语法有什么区别吗?
我不熟悉C语言。Get有不同的语法;设置属性。像C# 是得到;设置属性语法有什么区别吗?,c#,properties,automatic-properties,C#,Properties,Automatic Properties,我不熟悉C语言。Get有不同的语法;设置属性。像 public string Name { get { return this.name; } set { this.name = value; } } public string Name { get { return _name; } set { _name = value; } } protected string
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
public string Name
{
get { return _name; }
set { _name = value; }
}
protected string Name { get; set; }
这些语法之间有什么区别?以下不同的语法对功能有影响吗?或者所有语法都将执行相同的功能?前两个语法完全相同,因为您可以省略
这个
关键字
第三个功能完全相同,但会自动生成支持字段,使代码更短,更易于编写。请阅读链接的答案。如果不清楚,请告诉我们。目前您的问题与链接问题重复。谢谢。我从下面的链接中得到了答案:)请使用这个网站和谷歌的搜索功能。这个问题已经被问过多次了,所以应该很容易找到。