Code Listings 5
Code Listings 5
Chapter 7 - Collections
Enumeration
Low-level use of IEnumerable and IEnumerator
string s = "Hello";
while (rator.MoveNext())
{
char c = (char) rator.Current;
Console.Write (c + ".");
}
Console.WriteLine();
// Equivalent to:
foreach (char c in s)
Console.Write (c + ".");
Disposing enumerators
IEnumerable<char> s = "Hello";
void Main()
{
Count ("the quick brown fix".Split()).Dump();
}
void Main()
{
foreach (int element in new MyCollection())
Console.WriteLine (element);
}
void Main()
{
foreach (int element in new MyGenCollection())
Console.WriteLine (element);
}
Iterator method
void Main()
{
foreach (int i in Test.GetSomeIntegers())
Console.WriteLine (i);
}
void Main()
{
foreach (int i in new MyIntList())
Console.WriteLine (i);
}
void Main()
{
foreach (int i in new MyIntList())
Console.WriteLine (i);
}
void IDisposable.Dispose() {}
}
}
Arrays
Dictionaries
Immutable Collections
Frozen Collections
C# 12
in a Nutshell
About the Book
Code Listings
C# 12 in a Nutshell
C# 10 in a Nutshell
C# 9.0 in a Nutshell
C# 8.0 in a Nutshell
C# 7.0 in a Nutshell
Extras
Contact