Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么可以';t单个系统。数组元素可以通过C#中的索引访问?_C#_Oop - Fatal编程技术网

为什么可以';t单个系统。数组元素可以通过C#中的索引访问?

为什么可以';t单个系统。数组元素可以通过C#中的索引访问?,c#,oop,C#,Oop,以以下为例: class MyArray { private Array _array; public MyArray(Array array) { _array = array; } public object this[int index] { get { return _array[index]; } set { _array[index]=value; } } } 这将返回编译错误“此处无法访

以以下为例:

class MyArray {
    private Array _array;

    public MyArray(Array array) {
        _array = array;
    }

    public object this[int index] {
        get { return _array[index]; }
        set { _array[index]=value; }
    }
 }
这将返回编译错误“此处无法访问专用索引器'This'”

但是,如果将_数组声明为对象[],则此函数可以正常工作


这与值数组和引用数组之间的差异有关吗?

您不应该使用
数组

Array类是支持数组的语言实现的基类。但是,只有系统和编译器可以显式地从数组类派生。用户应该使用该语言提供的数组结构


您不应该使用
数组

Array类是支持数组的语言实现的基类。但是,只有系统和编译器可以显式地从数组类派生。用户应该使用该语言提供的数组结构


您可以看到类数组的描述:

提供用于创建、操作、搜索和排序的方法 数组,从而作为公共空间中所有数组的基类 语言运行时


该类没有索引器。如果您正在处理数组,则可以使用object[]或使用List,因为您可以看到类数组的描述:

提供用于创建、操作、搜索和排序的方法 数组,从而作为公共空间中所有数组的基类 语言运行时


该类没有索引器。如果您正在处理数组,则可以改用object[]或使用List

数组对象的维数不可预测,编译器无法检查索引表达式是否正确。数组对象的维数不可预测,编译器无法检查索引表达式是否正确。