且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在.NET数组只能实现IEnumerable而不是IEnumerable的< T>?

更新时间:2022-01-27 21:33:34

阵列都实施的IEnumerable< T> ,但它是作为的专业知识的CLI部分有数组。许多工具将不再显示此实现。看到言论段开始注意到在文档(文档早期.NET版本:外观为重要块)

Arrays do implement IEnumerable<T>, but it is done as part of the special knowledge the CLI has for arrays. Many tools will not show this implementation. See the paragraph in the remarks starting "Starting with the .NET Framework 2.0" note in the documentation (documentation for earlier .NET versions: look for the "Important" block).

您可以添加一个转换:

return ((IEnumerable<T>)_array).GetEnumerator();