c#中属性get set 如何使用
求解答一下 !!!
程序代码:
class A { private string s = null; public string S { get { Console.WriteLine("Getting S."); return s; } set { Console.WriteLine("Setting S."); this.s = value; } } } static void Main() { A a = new A(); a.S = "Test"; // 显示 "Setting S." string s = a.S; // 显示 "Getting S." }