Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
| string smessage=string.Empty; oContacts.ForEach(delegate(Contact oContact) { smessage += oContact.ToString() + Environment.NewLine; } ); MessageBox.Show(smessage); |
| //AsReadOnly() retourne la collection mais en lecture seule (ici l'edition dans le datagridview sera impossible) dataGridView1.DataSource = oContacts.AsReadOnly(); |
| // extrait à partir de la position 2 de la collection, 3 éléments (contact) List<Contact> oRangeContacts = oContacts.GetRange(2, 3); |
| Contact oContact = oContacts.Find(StartWith); MessageBox.Show(oContact.ToString()); |
| Contact oContact = oContacts.FindLast(StartWith); int nIndex =oContacts.IndexOf(oContact); |
| MessageBox.Show(oContacts.FindIndex(StartWith).ToString()); |
| MessageBox.Show(oContacts.FindLast(StartWith).ToString()); |
| Contact oContact = oContacts.FindLast(StartWith); int nIndex =oContacts.LastIndexOf(oContact); |
| MessageBox.Show(oContacts.FindLastIndex(StartWith).ToString()); |
| dataGridView1.DataSource = oContacts.FindAll(StartWith); |
| oContacts.Sort(); |
| oContacts.Sort(new Contact.ContactNameComparer(SorterMode.Ascending)); |
| Si vous ne connaissez pas bien comment trier avec IComparable et IComparer vous pouvez regarder cet article Ou encore regarder cette source ;) |
| Contact[] ContactArrray; ContactArrray = new Contact[5]; oContacts.CopyTo(ContactArrray); dataGridView1.DataSource = ContactArrray; |
| Contact[] ContactArrray = oContacts.ToArray(); |
| List<Person> ListPerson = oContacts.ConvertAll(new Converter<Contact, Person>(ConvertToPerson)); dataGridView1.DataSource = ListPerson; |
| public Person ConvertToPerson(Contact oContact) { return new Person(oContact.ID, oContact.Name, oContact.FirstName, oContact.Email); } |
| public class Person { private int _ID; private string _Name; private string _FirstName; private string _Email; public Person() { } public Person(int ID, string Name, string FirstName, string Email) { this.ID = ID; this.Name = Name; this.FirstName = FirstName; this.Email = Email; } public int ID { get { return _ID; } set { _ID = value; } } public string Name { get { return _Name; } set { _Name = value; } } public string FirstName { get { return _FirstName; } set { _FirstName = value; } } public string Email { get { return _Email; } set { _Email = value; } } } |
| Contact oContact = oContacts.Find(StartWith); MessageBox.Show(oContacts.Contains(oContact).ToString()); |
| MessageBox.Show(oContacts.Exists(StartWith).ToString()); |
| MessageBox.Show(oContacts.TrueForAll(StartWith).ToString()); |
| MessageBox.Show(oContacts[1].Equals(oContact).ToString()); |
| MessageBox.Show(oContacts.GetType().ToString()); |
| oContacts.Reverse(); |
| MessageBox.Show("Nombre de contacts dans la collection : " + oContacts.Count.ToString()); |
| MessageBox.Show(oContacts.Capacity.ToString()); |