标签:
1.属性
//属性的2种写法 public class person { private string _name; public string Name { get { return _name; } set { _name=value; } } public int Age { get; set; } }
2.索引器
//外部调用 person p=new person; sting str=p[0] public class person { private string _name; public string Name { get { return _name; } set { _name=value; } } public int Age { get; set; } public string Email { get; set; } //也可以用 sting 键值,也可以多个参数 //可以重载,PS:public string this[int index],public string this[string key] public string this[int index] { get { string result=""; switch(index) { case 0: result=this.Name; break; case 1: result=this.Age; break; case 2: result=this.Email; break; } return result; } } }
标签:
原文地址:http://www.cnblogs.com/milest/p/4581860.html