次のコードは、次の Web ページから取得したものです: http://msdn.microsoft.com/en-us/magazine/cc188707.aspx
int[] values = new int[] {1, 2, 3, 4, 5};
IEnumerator e = ((IEnumerable)values).GetEnumerator();
while(e.MoveNext())
{
Console.Write(e.Current.ToString() + " ");
}
Array クラスが IEnumerable にキャストされるのはなぜですか? Array クラスは、Web ページhttp://msdn.microsoft.com/en-us/library/system.array.aspxに示されているように GetEnumerator を実装します。