|
Exemple 14-37 extrait du chapitre Les mécanismes utilisables dans C#
Exemple 14-36< > Exemple 14-38
Cet exemple peut être compilé avec la ligne de commande: csc.exe /target:exe Exemple_14_37.cs Erreurs: 0 Avertissements: 0 Remarque:
Exemple_14_37.cs
public class Personnes : System.Collections.IEnumerable{
string[] m_Noms;
public Personnes(params string[] noms){
m_Noms = new string[noms.Length];
noms.CopyTo(m_Noms, 0);
}
// La méthode GetEnumerator() de IEnumerable.
public System.Collections.IEnumerator GetEnumerator(){
foreach (string s in m_Noms)
yield return s;
}
}
class Program {
static void Main() {
Personnes arrPersonnes = new Personnes(
"Michel", "Christine", "Mathieu", "Julien");
foreach (string s in arrPersonnes)
System.Console.WriteLine(s);
}
}
Copyright Patrick Smacchia 2006 2007
|