Although arrays in C# appear to implement IList
In reality, arrays implement System.Collections.IList, not System.Collections.Generic.IList
However, the CLR generates specific array types that could potentially implement these interfaces. But even for these concrete array types, casting to IEnumerable
This is due to "quacks-like-a-duck" typing, where the compiler and CLR recognize arrays as implementing IList
Even though the Count property is not explicitly implemented, the CLR provides an internal getter using a cast to the T[] array.
This behavior, while somewhat unconventional, allows for a seamless and efficient implementation of IList
The above is the detailed content of Why Don't C# Arrays Directly Implement `IList`, and How Do They Still Seem To?. For more information, please follow other related articles on the PHP Chinese website!