|
Listing 14-39 extracted from chapter Unsafe code, exceptions, anonymous methods, iterators
Listing 14-38< > Listing 14-40
This listing can be compiled with the command line: csc.exe /target:library Example_14_39.cs Errors: 0 Warnings: 0
Example_14_39.cs
using System.Collections.Generic;
using System.Collections;
public class Persons : IEnumerable<string> {
string[] m_Names;
public Persons(params string[] names) {
m_Names = new string[names.Length];
names.CopyTo(m_Names, 0);
}
IEnumerator<string> IEnumerable<string>.GetEnumerator() {
return PRIVGetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return PRIVGetEnumerator();
}
private IEnumerator<string> PRIVGetEnumerator() {
foreach (string s in m_Names)
yield return s;
}
}
Copyright Patrick Smacchia 2006 2007
|