c# 不确定行数的二维数组的问题
如题,我想得到这样一个二维数组:1 2
3 4
5 6
7 8
9 10
11 12
...
这个二维数组的列数是固定为2的,但是行数不确定。
我上网查了说用arraylist或者list,可是没找到明确的代码,请大家回复时能不能给出明确的代码呢?谢谢了 --------------------编程问答-------------------- 数组的行数本来就是不确定的。你声明参数时,在类型上写过行数吗? --------------------编程问答-------------------- 那你用List<int[]> 好了。 --------------------编程问答--------------------
主要问题是我数组里的数,每次都是经过程序计算再循环里一行一行添加的。不设行数的声明通不过啊 --------------------编程问答--------------------
嗯,用list<string[]>或者arraylist都行,但是我写的代码添加完了,存放在arraylist里的全为最后一个,大侠你能写下代码么? --------------------编程问答--------------------
List<string[]> test = new List<string[]>();
for (int i = 1; i <= 10; i+=2)
{
string[] temp = new string[] { i.ToString(), (i + 1).ToString() };
test.Add(temp);
}
你可以把你的代码贴出来,让大家帮你看看错在哪里。 --------------------编程问答-------------------- 定一个实体类
class cc--------------------编程问答-------------------- 那就就用泛型好了 List<T>
{
public int a1{get;set;}
public int a2{get;set;}
}
List<cc> lc=new List<cc>();
lc.Add(new cc{a1=1;a2=2})
......
--------------------编程问答--------------------
--------------------编程问答--------------------
private List<string[]> input_list_name_seq = new List<string[]>();
protected bool check()
{
if (flag)
{
string input_text = tbox_input.Text;
lines = input_text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int hang = -1;
string[] arr_input_name_seq = new string[2];
for (int h = 0; h < lines.Length & hang<100; h++)
{
//if (lines[h] == "\r") continue;
if (lines[h].Substring(0, 1) == ">")
{
if (hang != -1&arr_input_name_seq[1]!=null)
{
if (arr_input_name_seq[1].Length - k < lamat)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('Please correct input Lambda parameter,it should be short than cds'length - k')</script>");
return false;
}
input_list_name_seq.Add(arr_input_name_seq);
}
hang++;
arr_input_name_seq[0] = lines[h];
arr_input_name_seq[1] = "";
}
else
{
arr_input_name_seq[1] += lines[h];
}
}
}
}
补充:.NET技术 , C#