.net Get与Set属性, 求解释!!!!!!!!!!!!!!!!!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
test t = new test();
t.Name = "3"; //设置这个name,我并没有执行get方法,而应该是set。为什么这里监视到t.name = "1"?
Console.WriteLine(t.Name);
Console.ReadLine(); //最后输出结果为 "1"
}
}
public class test
{
private string name;
public string Name
{
get { if (true) { return "1"; } }
set { name = value; }
}
}
}
这是我对于属性的理解,
不知道对你有帮助没
http://www.cnblogs.com/youmeng/archive/2013/06/06/3122784.html
[解决办法]
楼主,你永远都在return 1。。。。。