C# foreach语句译文上

oreach语句作用简介:

迭代语句标识符。

foreach 语句为类型实例中实现 System.Collections.IEnumerable 或 System.Collections.Generic.IEnumerable<T> 接口的每个元素执行语句或语句块。 foreach 语句不局限于这些类型,它可应用于满足以下条件的任何类型的实例:

  • 具有公共无参数 GetEnumerator 方法,其返回类型为类、结构或接口类型。
  • GetEnumerator 方法的返回类型具有公共 Current 属性和公共无参数 MoveNext 方法(其返回类型为 Boolean)。

C# foreach语句译文上