数组的数组 [英] Array of Arrays

查看:83
本文介绍了数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建数组在C#中的数组?我已阅读有关创建交错数组,但我不知道那是否要去关于它的最好的方式。我是想实现这样的:

How do you create an array of arrays in C#? I have read about creating jagged arrays but I'm not sure if thats the best way of going about it. I was wanting to achieve something like this:

string[] myArray = {string[] myArray2, string[] myArray3}

然后我就可以像 myArray.myArray2访问[0];

我知道,code将无法正常工作,但只是作为一个例子来解释我的意思。

I know that code won't work but just as an example to explain what I mean.

感谢。

推荐答案

数组或多维数组的数组的简单示例如下:

Simple example of array of arrays or multidimensional array is as follows:

int[] a1 = { 1, 2, 3 };
int[] a2 = { 4, 5, 6 };
int[] a3 = { 7, 8, 9, 10, 11 };
int[] a4 = { 50, 58, 90, 91 };

int[][] arr = {a1, a2, a3, a4};

要测试数组:

for (int i = 0; i < arr.Length; i++)
{
    for (int j = 0; j < arr[i].Length; j++)
    {
        Console.WriteLine("\t" +  arr[i][j].ToString());
    }
}

这篇关于数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆