November 2002
Intermediate to advanced
560 pages
11h 16m
English
Like Visual Basic .NET and Perl, C# provides a foreach statement, which can be used to enumerate over objects that implement IEnumerable.
When writing containers that store value types, using the IEnumerable design pattern has an unfortunate side effect. Because IEnumerable.GetEnumerator returns an IEnumerator and IEnumerator.Current is of type object, the only way to return values from an enumerator is as an object. For value types, this means that the Current property boxes the value type and then returns it to the client, which immediately unboxes it. This boxing and unboxing is unfortunate from a performance standpoint.
To get around this problem, C# supports an alternative way of doing enumerators. If ...
Read now
Unlock full access