扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
1 public class Person { 2 3 private string firstName; 4 private string lastName; 5 private int age; 6 7 public string FirstName { 8 9 get { 10 return this.firstName; 11 } 12 set { 13 this.firstName = value; 14 } 15 } 16 17 public string LastName { 18 19 get { 20 return this.lastName; 21 } 22 set { 23 this.lastName = value; 24 } 25 } 26 27 public int Age { 28 29 get { 30 return this.age; 31 } 32 set { 33 this.age = value; 34 } 35 } 36 } |
1 public class Person { 2 3 public string FirstName { 4 get; set; 5 } 6 7 public string LastName { 8 get; set; 9 } 10 11 public int Age { 12 get; set; 13 } 14 } |
1 //.NET 2.0: 2 Person person = new Person(); 3 person.FirstName = "小兵"; 4 person.LastName = "网魂"; 5 person.Age = 23; 6 //.NET 3.x: 7 Person person = new Person { FirstName = "小兵", LastName = "网魂", Age = 23}; |
1 //.NET 2.0; 2 List<Person> people = new List<Person>(); 3 4 people.Add( new Person { FirstName = "小兵", LastName = "网魂", Age = 23 } ); 5 people.Add( new Person { FirstName = "QQing", LastName = "Lai", Age = 22 } ); 6 people.Add( new Person { FirstName = "Xbing", LastName = "My", Age = 20 } ); 7 8 //.NET 3.x; 9 List<Person> people = new List<Person> { 10 new Person { FirstName = "小兵", LastName = "网魂", Age = 23 }, 11 new Person { FirstName = "QQing", LastName = "Lai", Age = 22 }, 12 new Person { FirstName = "Xbing", LastName = "My", Age = 20 } 13 };//记得这边是要有";"的,不然就会出错的。 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者