.NET Framework - IEnumerable 接口 & IEnumerator 接口

创建时间:
2018-10-06 18:12
最近更新:
2018-10-06 19:02

Resource - MSDN

  1. System.Collections.Generic.IEnumerable<T> 接口
  2. System.Collections.Generic.IEnumerator<T> 接口
  1. System.Collections.IEnumerable 接口
  2. System.Collections.IEnumerator 接口
  3. Tony Praise: 以上两个页面有同一个示例,该示例很好地表现了这两个接口的本质。
  1. 示例 - 集合类中实现 IEnumerable 接口

Source Code of System.Collections.IEnumerable from JetBrains dotPeek 1.0 at 2018-10-06

Complete Copy:

// Type: System.Collections.IEnumerable
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Runtime.InteropServices;

namespace System.Collections
{
  [Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
  [ComVisible(true)]
  [__DynamicallyInvokable]
  public interface IEnumerable
  {
    [DispId(-4)]
    [__DynamicallyInvokable]
    IEnumerator GetEnumerator();
  }
}

Source Code of System.Collections.Generic.IEnumerable<out T> from JetBrains dotPeek 1.0 at 2018-10-06

Complete Copy:

// Type: System.Collections.Generic.IEnumerable`1
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Collections;
using System.Runtime.CompilerServices;

namespace System.Collections.Generic
{
  [TypeDependency("System.SZArrayHelper")]
  [__DynamicallyInvokable]
  public interface IEnumerable<out T> : IEnumerable
  {
    [__DynamicallyInvokable]
    IEnumerator<T> GetEnumerator();
  }
}

Source Code of System.Collections.IEnumerator from JetBrains dotPeek 1.0 at 2018-10-06

Complete Copy:

// Type: System.Collections.IEnumerator
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Runtime.InteropServices;

namespace System.Collections
{
  [Guid("496B0ABF-CDEE-11d3-88E8-00902754C43A")]
  [ComVisible(true)]
  [__DynamicallyInvokable]
  public interface IEnumerator
  {
    [__DynamicallyInvokable]
    object Current { [__DynamicallyInvokable] get; }

    [__DynamicallyInvokable]
    bool MoveNext();

    [__DynamicallyInvokable]
    void Reset();
  }
}

Source Code of System.Collections.Generic.IEnumerator<out T> from JetBrains dotPeek 1.0 at 2018-10-06

Complete Copy:

// Type: System.Collections.Generic.IEnumerator`1
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System;
using System.Collections;

namespace System.Collections.Generic
{
  [__DynamicallyInvokable]
  public interface IEnumerator<out T> : IDisposable, IEnumerator
  {
    [__DynamicallyInvokable]
    T Current { [__DynamicallyInvokable] get; }
  }
}