Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
| private void button1_Click(object sender, EventArgs e) { // 1 avec méthode anonyme List<Contact> result = Contacts.FindAll(delegate(Contact oContact) { return oContact.ContactAge > 20; }); dataGridView1.DataSource = result; } |
| private void button1_Click(object sender, EventArgs e) { // 2 avec un Predicate (qui est un delegue) // Predicate<T> predicate = new Predicate<T>(bool(T) target) Predicate<Contact> predicate = new Predicate<Contact>(FindContacts); List<Contact> result = Contacts.FindAll(predicate); dataGridView1.DataSource = result; } public bool FindContacts(Contact oContact) { return oContact.ContactAge > 20; } |
| private void button1_Click(object sender, EventArgs e) { List<Contact> result = Contacts.FindAll(FindContacts); dataGridView1.DataSource = result; } public bool FindContacts(Contact oContact) { return oContact.ContactAge > 20; } |
| public bool nommethod(T obj) { // test Return booleen; } |
| private void button2_Click(object sender, EventArgs e) { Contacts.Sort(delegate(Contact x, Contact y) { return Comparer<string>.Default.Compare(x.ContactName, y.ContactName); }); } |
| private void button2_Click(object sender, EventArgs e) { // Comparison<T> comparison =new Comparison<T>(int (T,T)target); Comparison<Contact> comparison = new Comparison<Contact>(SortContacts); Contacts.Sort(comparison); dataGridView1.DataSource = Contacts; } public int SortContacts(Contact x, Contact y) { return Comparer<string>.Default.Compare(x.ContactName, y.ContactName); } |
| private void button2_Click(object sender, EventArgs e) { Contacts.Sort(SortContacts); dataGridView1.DataSource = Contacts; } public int SortContacts(Contact x, Contact y) { return Comparer<string>.Default.Compare(x.ContactName, y.ContactName); } |
| public int nommethod(T x, T y) { return Comparer<K>.Default.Compare(x.property, y.property); } |