![](/Emoticons/emsmile.gif)
class EntryPoint
{
[STAThread]
static void Main(string[] args)
{
Test test = new Test();
test.Name = "yicone";
test.Name = "yicone";
test.Name = "yic";
Console.ReadLine();
}
}
public class Test
{
int i = 1;
public string name;
public string Name
{
get{return name;}
set
{
if(value == Name)
{
Console.WriteLine("第{0}次set name属性失败!", i++);
Console.WriteLine("原因:与当前Test类的实例的Name属性值相同,不需要更改");
return;
}
name = value;
Console.WriteLine("第{0}次set name属性成功", i++);
}
}
}
{
[STAThread]
static void Main(string[] args)
{
Test test = new Test();
test.Name = "yicone";
test.Name = "yicone";
test.Name = "yic";
Console.ReadLine();
}
}
public class Test
{
int i = 1;
public string name;
public string Name
{
get{return name;}
set
{
if(value == Name)
{
Console.WriteLine("第{0}次set name属性失败!", i++);
Console.WriteLine("原因:与当前Test类的实例的Name属性值相同,不需要更改");
return;
}
name = value;
Console.WriteLine("第{0}次set name属性成功", i++);
}
}
}
p.s. 调整了措词,以避免不必要的误会.