如何将变量放在单个数组中 [英] How Do I Put variables In Single Array
本文介绍了如何将变量放在单个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
I have
a=1,2,3;
b=20,30,40;
c=12,13,14;
如何将它们放在单个数组中
how do i put them in single array
推荐答案
可能:
Maybe:
int[] a = new int[] { 1, 2, 3 };
int[] b = new int[] { 20, 30, 40 };
int[] c = new int[] { 12, 13, 14 };
int[][] array = new int[][] { a, b, c };
您的代码示例不起作用:您不能使用像那个在C#
但是我假设你要创建一个包含行列的数组。
如果是这样,有两种方法。
多维数组:
Your code example doesn't work: you can't use staff like that in C#
But what I assume is that you want to create an array that contains rows a columns.
If so, there are two ways.
Multidimensional array:
int[,] arr = new int[3,3];
这会创建一个总是大小相同的数组。你可以很容易地将它初始化为你的数据
This creates an array that is always the same size. You can initialise it to your data very easily
int[,] arr = new int[,] {{1,2,3}, {1,2,3}, {1,2,3}};
锯齿状阵列:
Jagged arrays:
int[][] arr = new int[3][];
这篇关于如何将变量放在单个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文