日期:2014-05-17  浏览次数:20408 次

问一个基础的数组问题
int[,] ar = new int[2,3];


我有一个方法,参数是一个一维int数组,我想获取ar中的第二行数组成的一维数组。 int[] t = ar[1];不对吗?

------解决方案--------------------
int[] t = Enumerable.Range(0, ar.GetLength(1)).Select(x => ar[1, x]).ToArray();
------解决方案--------------------
参数传送,感觉你用这种方法不是很好,应该改用类.参数是一个list<T>,T中包含有id和一个list<T>

public 

大概格式:

public class ListItem
{
public int col1 {get;set;}
public int col2 {get;set;}
public int col3 {get;set;}
}

public class ListParam
{
public int ID {get;set;}
public List<ListItem> list {get;set;}
}

------解决方案--------------------
int[2,3]和int[2][3]貌似不一样
------解决方案--------------------
            int[,] ar = new int[2, 3];
            int[] t = new int[ar.GetLength(1)];
            for (int a = 0; a != ar.GetLength(1); a++) t[a] = (int)ar.GetValue(1, a);/*t[a] = ar[1, a]; */