static void Main(string[] args) { People people = new People( new Person("张三", 20, new DateTime(1991, 1, 2)), new Person("李四", 22, new DateTime(1989, 2, 3)), new Person("王五", 25, new DateTime(1986, 3, 10)) ); Person person6 = new Person("赵六", 26, new DateTime(1985, 3, 12)); people.Add(person6); Person[] persons = new Person[5]; people.CopyTo(persons, 0); foreach (Person person in people) { Console.WriteLine(string.Format("name: {0} age: {1} birthday: {2}", person.Name, person.Age, person.BirthDay.ToString())); } Console.WriteLine("===============Person Array Start============"); for (int i = 0; i <= 1; i++) { Console.WriteLine(string.Format("name: {0} age: {1} birthday: {2}", persons[i].Name, persons[i].Age, persons[i].BirthDay.ToString())); } //foreach (Person person in persons) //{ // Console.WriteLine(string.Format("name: {0} age: {1} birthday: {2}", person.Name, person.Age, person.BirthDay.ToString())); //} Console.WriteLine("===============Person Array End============"); //“赵六” Console.WriteLine("========a person start======="); Person person_6 = people["赵六"]; Console.WriteLine(string.Format("name: {0} age: {1} birthday: {2}", person_6.Name, person_6.Age, person_6.BirthDay.ToString())); Console.WriteLine("========a person end======="); Console.ReadKey(); }
public void Remove(Person person) { this._persons.Remove(person); }
private void Replace(int index, Person newPerson) { this._persons[index] = newPerson; }
public void Insert(int index, Person person) { this._persons.Insert(index, person); }
public int IndexOf(Person value) { return IndexOf(value); }
public void CopyTo(Person[] persons, int index) { //((ICollection)this).CopyTo(persons, index); this._persons.CopyTo(persons, index); }
public bool Contains(Person person) { return this._persons.Contains(person); }
public void Add(Person person) { this._persons.Add(person); }