首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

多维数组的索引该如何设置

2012-12-26 
多维数组的索引该怎么设置以下一维数组,测试通过public class aaa{int[] _numberspublic int this[int in

多维数组的索引该怎么设置
以下一维数组,测试通过


    public class aaa
    {
        int[] _numbers;
        public int this[int index1]
        {
            get
            {
                return _numbers[index1];
            }
        }
    }

想在多维数组中,该怎么设置?

    public class bbb
    {
        int[][] _numbers;
        public int this[int index1][int index2] //这里该怎么设置?
        {
            get
            {
                return _numbers[index1][index2];
            }
        }
    }

[解决办法]
这样貌似也行:
public class bbb
{
int[][] _numbers;
public int[] this[int index] //这里该怎么设置?
{
get
{
return _numbers[index];
}
}
}

调用bbb b = new bbb();
int value=b[3][2];

热点排行