I just download the .Net framework source code from http://referencesource.microsoft.com/netframework.aspx It’s Net_4.msi. But after I installed it, I cannot find IEnumerator code file. I just wonder why Net_4.msi does not include all of .Net class.
Update: Thanks for replies and sorry for the confusion.
I am not asking for the definition of IEnumerator.
I think that “Net_4.msi” should include all of .Net classes/ interfaces’ source code files.
Such as in the folder Net_4\Source\ndp\clr\src\BCL\System\Collections
, you may find IList.cs, ICollection.cs, IDictionary.cs and IEnumerable.cs.
These 4 files are IList, ICollection, IDictionary and IEnumerable source code files respectively.
Please see this image.
But I cannot find the file: IEnumerator.cs. I just curi开发者_开发问答ous to know where IEnumerator.cs is. Why does IEnumerator.cs not include in the “Net_4.msi”?
As loki points out, IEnumerator<T>
is an interface, not a concrete class, so there is no implementation. However, you could hunt around a bit and find an an example of how to implement the interface for your custom type(s).
To answer your question directly, it is defined in mscorlib.dll and this is the entire .NET 4.0 file:
#region Assembly mscorlib.dll, v4.0.30319
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
#endregion
using System;
using System.Collections;
namespace System.Collections.Generic
{
// Summary:
// Supports a simple iteration over a generic collection.
//
// Type parameters:
// T:
// The type of objects to enumerate.This type parameter is covariant. That is,
// you can use either the type you specified or any type that is more derived.
// For more information about covariance and contravariance, see Covariance
// and Contravariance in Generics.
public interface IEnumerator<out T> : IDisposable, IEnumerator
{
// Summary:
// Gets the element in the collection at the current position of the enumerator.
//
// Returns:
// The element in the collection at the current position of the enumerator.
T Current { get; }
}
}
IEnumerator is not a class, it's interface. There's just no code.
精彩评论