Generic interfaces

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
Exam 70-536 Study Guide

1. Types and collections

2. Process, threading,…
3. Embedding features
4. Serialization, I/O
5. .NET Security
6. Interop., reflection,…
7. Global., drawing, text

edit

Contents

ICollection

IList

IDictionary

IComparable

IComparer

IEqualityComparer

IEnumerable

IEnumerator

IEnumerator<T> supports a type safe iteration over a generic collection. It has all the same members as IEnumerator (It "inherits" from IEnumerator), however it also has a Current property of type T. The T Current property allows retrieving the current item in the iteration without requiring a cast from object.

When implementing the generic IEnumerator, implement the nongeneric Current property explicitly:

public class MyEnumerator<T> : IEnumerator<T>{
 
   // Implement the Generic Current implicitly 
   // so it is always visible
   public T Current {
      get{
         //...
         }
      }
 
   // Implement the nonGeneric Current explicitly 
   // so it is only visible with a 
   // nongeneric IEnumertor refererence
   public object IEnumator.Current {
      get{
         //...
         }
      }
 
   //...
 
   }

See IEnumerator

IHashCodeProvider


Personal tools