Adr*_*ien 5 c# properties ambiguity
我最近开始学习C#.我刚刚了解了属性,并决定制作一个简单的程序,以便更好地理解它们.这是我写的代码:
class Dog
{
private int weight;
private string colour;
public string colour { get; set; }
public Dog(int theWeight, string theColour)
{
weight = theWeight;
colour = theColour;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个模棱两可的错误.据我所知,这不应该发生.
歧义错误是你命名字段和属性同名"颜色".更改属性定义fe
public string Colour
{
get { return colour;}
set { colour = value;}
}
Run Code Online (Sandbox Code Playgroud)