March 2004
Intermediate to advanced
560 pages
26h 47m
English
public sealed class CharEnumerator : IEnumerator, ICloneable { // Properties public char Current { get; } // Methods public object Clone (); public bool MoveNext (); public void Reset (); // Explicit Interface Members object IEnumerator.Current { get; } }
|
BA Our reason for adding this class to the BCL was not that we felt there was a huge demand for enumerating characters. It was required to enable efficient support for applying foreach over strings. Simply using IEnumerator would have caused a boxing operation for each character accessed out of the string.
string s = "John Smith";
foreach (char c in s) {
Console.WriteLine ("{0}-", c);
}
A side note on this is that the C# compiler now does not even use this class. It special-cases ... |
Read now
Unlock full access