Casting array to IEnumerable

后端 未结 3 1365
傲寒
傲寒 2020-12-02 21:53

Assume you have a basic Employee class as such:

class Employee
{
   public string Name;
   public int Years;
   public string Department;
}
         


        
3条回答
  •  春和景丽
    2020-12-02 22:33

    From the documentation:

    In the .NET Framework version 2.0, the Array class implements the System.Collections.Generic.IList, System.Collections.Generic.ICollection, and System.Collections.Generic.IEnumerable generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools. As a result, the generic interfaces do not appear in the declaration syntax for the Array class, and there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations).

    Thus, your Employee[] implements IEnumerable.

提交回复
热议问题