如何在C#中创建锯齿状数组? [英] How to create jagged arrays in c#?

查看:90
本文介绍了如何在C#中创建锯齿状数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉C.在哪里可以这样写:

I'm familiar with C. Where I can write like this:

uint array[0xFFFF][20];

但是我不知道如何在Csharp中做到这一点.我尝试了所有MS教程和其他教程,但是没有运气.

But I've no idea how to do this in Csharp. I tried all MS tutorials and other tutorials but no luck.

有人可以帮我吗?

推荐答案

官方教程.基本上,您首先创建外部"数组,然后循环通过它,然后分别创建每个内部"数组.

Official tutorial. Basically you create the "outer" array first, and then loop trough it, and create each "inner"array individually.

两个例子:

int[][] a = new int[] { new int[]{ 1, 2 }, new int[]{ 3, 4, 5, 6, 7 }};

int[][] c = new int[100][];
for (int i = 0; i < c.length; i++) c[i] = new int[5];

如果仅需要2D矩形阵列,则可以使用int[,] b = new int[10, 7];.

If you need only a 2D rectangular array, you can use int[,] b = new int[10, 7];.

这篇关于如何在C#中创建锯齿状数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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