标签:
class Person { private string _name; //姓名 private int _age; //年龄 //创建Person对象 public Person(string Name, int Age) { this._name= Name; this._age = Age; } //姓名 public string Name { get { return _name; } } //年龄 public int Age { get { return _age; } } } //创建Person对象 Person p1 = new Person("张三", 30); Person p2 = new Person("李四", 20); Person p3 = new Person("王五", 50); //创建类型为Person的对象集合 List<Person> persons = new List<Person>(); //将Person对象放入集合 persons.Add(p1); persons.Add(p2); persons.Add(p3); //输出第2个人的姓名 Console.Write(persons[1].Name);
标签:
原文地址:http://www.cnblogs.com/chenzhongdong/p/4777449.html