gpt4 book ai didi

c# - 数组是否实现了 IEnumerable

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:47 26 4
gpt4 key购买 nike

我知道基本抽象 Array 类没有实现通用 IEnumerable

public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable
{
...
}

所以当我创建像 int[] i; 这样的派生数组类时或 string[] s; , 他们是否实现 IEnumerable<T> ?我怎样才能看到[]的源代码? ?

最佳答案

这里是官方说法

Array Overview

An array has the following properties:

  • An array can be Single-Dimensional, Multidimensional or Jagged.

  • The number of dimensions and the length of each dimension are established when the array instance is created. These values can't be changed during the lifetime of the instance.

  • The default values of numeric array elements are set to zero, and reference elements are set to null.

  • A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null.

  • Arrays are zero indexed: an array with n elements is indexed from 0 to n-1.

  • Array elements can be of any type, including an array type.

  • Array types are reference types derived from the abstract base type Array. Since this type implements IEnumerable and IEnumerable<T>, you can use foreach iteration on all arrays in C#.

关于c# - 数组是否实现了 IEnumerable<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56472011/

26 4 0