110,499
社区成员
发帖
与我相关
我的任务
分享
using System.Runtime.InteropServices;
namespace System.Collections
{
// 摘要:
// Exposes the enumerator, which supports a simple iteration over a non-generic
// collection.
[ComVisible(true)] //[1] 这个标志是什么意思
[Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")] //[2] 这个标志是什么意思
public interface IEnumerable
{
// 摘要:
// Returns an enumerator that iterates through a collection.
//
// 返回结果:
// An System.Collections.IEnumerator object that can be used to iterate through
// the collection.
[DispId(-4)] //[3] 这个标志是什么意思
IEnumerator GetEnumerator();
}
}
this.current = default(T);// 这句话是什么意思,default 关键字,有什么作用?
public Enumerator<T> GetEnumerator()
{
return new Enumerator<T>((List<T>) this);
}
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{
private List<T> list;
private int index;
private int version;
private T current;
internal Enumerator(List<T> list)
{
this.list = list;
this.index = 0;
this.version = list._version;
this.current = default(T);
}
public void Dispose()//打开发现这个方法没有现实体
{
}
public bool MoveNext()
{
List<T> list = this.list;
if ((this.version == list._version) && (this.index < list._size))
{
this.current = list._items[this.index];
this.index++;
return true;
}
return this.MoveNextRare();
}
private bool MoveNextRare()
{
if (this.version != this.list._version)
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
}
this.index = this.list._size + 1;
this.current = default(T);
return false;
}
public T Current
{
get
{
return this.current;
}
}
object IEnumerator.Current
{
get
{
if ((this.index == 0) || (this.index == (this.list._size + 1)))
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
}
return this.Current;
}
}
void IEnumerator.Reset()
{
if (this.version != this.list._version)
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
}
this.index = 0;
this.current = default(T);
}
}
IEnumerator GetEnumerator();
IEnumerable ieInt = new int[] { 1, 2, 3, 4 };
IEnumerable ieString = new List<string> {"小菜","大侠","高手" ,"苯旦"};