我有两个班:

//The class with the Main method
    Six ujhb = new(4);
//fill in all the arrays but not the inner arrays
    for(int i = 0; i < ujhb.Size; i++) {
        ujhb[i] = new int[i+1];
        Console.WriteLine(ujhb[i]);
    }
//get a value of a specific inner array
    Console.WriteLine(ujhb[2][0]);

class Six {

    int[][] a;
    public int Size;

    public Six(int v) {
        a = new int[v][];
        Size = v;
    }

    public int[] this[int index] {
        get {
            return a[index];
        }

        set {
            a[index] = value;
        }
    }
}

所以我有一个索引器,它获取一个数组或设置一个数组

Console.WriteLine(ujhb[2][0]);

考虑到索引器被告知返回int[]s而不是int[]s?

推荐答案

这是两次手术.

1.)ujhb[2]首先用index == 2调用索引器,后者返回一个数组(int[]).

2.)然后[0]访问该数组中索引0处的项.

基本上,它是:

var array = ujhb[2]; // indexer call
var item = array[0]; // array access
Console.WriteLine(item);

Csharp相关问答推荐

如何基于记录数组,在一次拍摄中更新单个MongoDB集合的多个记录中的子嵌入文档?

IComponition.获取IReadOnlyCollection的返回默认属性值

注册通用工厂的C# Dep注入

以自动方式注销Azure身份应用程序

将XPS转换为PDF C#

Blazor服务器端的身份验证角色

Blazor EventCallback<;MyType<;T>;>;

使用带有WithAppOnly()请求选项的pageIterator

Razor视图Razor页面指向同一端点时的优先级

如何在WPF的树视图中显示一个对象的两个或多个属性,其中只有一个是分层项?

在.NET MAUI.NET 8中如何防止按钮点击时出现灰色反馈

持有者安全定义未显示在Swagger.NET 8中

依赖项注入、工厂方法和处置困境

在被Interactive Server切换后,Blazor SSR页面无法正确加载JS

Blazor Fluent UI DialogService,<;FluentDialogProvider/>;错误

源代码生成器:CS8795分部方法';Class1.GetS2(字符串)';必须有实现部分,因为它有可访问性修饰符?

RCL在毛伊岛应用程序和Blazor服务器应用程序.Net 8.0中使用页面

如何将默认区域性更改为fr-FR而不是en-US?

c#在后台实现类型化数组

Maui:更改代码中的绑定字符串不会更新UI,除非重新生成字符串(MVVM)