c#没有办法直接调用二维数组的一维嘛? 如果你知道要调用的是哪一维!当然不用遍历!如果你还要判断的话!就一定要遍历.你可以把遍历的那段代码放在一个using中,这样会自动释放资源! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20100513/11/823236cd-cd29-4d58-b8a9-233a3b0ce9dc.html参考这帖子 如果你描述的没错,没有吧交错数组当成二维数组。那只能告诉你,一定要复制,不过可以优化。static void Main(string[] args){ int[,] arr2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; int[] arr1 = GetByRank(arr2, 1); foreach (int i in arr1) { Console.WriteLine(i); } Console.ReadKey();}public static int[] GetByRank(int[,] arr2, int rank){ int[] arr1 = new int[arr2.GetLength(1)]; IntPtr hArray = Marshal.UnsafeAddrOfPinnedArrayElement(arr2, 0 * arr2.GetLength(0)); Marshal.Copy(hArray, arr1, 0, arr1.Length); return arr1;} 有个测试的忘记修改了。忽略3楼 那个顶死的。static void Main(string[] args){ int[,] arr2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; int[] arr1 = GetByRank(arr2, 0); foreach (int i in arr1) { Console.WriteLine(i); } Console.ReadKey();}public static int[] GetByRank(int[,] arr2, int rank){ int[] arr1 = new int[arr2.GetLength(1)]; IntPtr hArray = Marshal.UnsafeAddrOfPinnedArrayElement(arr2, rank * arr2.GetLength(0)); Marshal.Copy(hArray, arr1, 0, arr1.Length); return arr1;} 大数据量模糊查询速度如何优化? 对于Try..Catch的一点疑问,欢迎讨论 诡异我问题 大批量TCP连接怎么处理? 如何知道字符串的长度是多少像素 如何在WinFrom中实现图片的放大缩小 请问有什么方法可以在一定时间内响应某个事件一次? Windows 服务程序 引入User32.DLL无效问题 求在C#下进行windows ad 编程的教程和实例!在线等待结帖 dll中没有命名空间就不能引用吗? 如何使用二分查找查数据? 有偿请人帮忙做个验证码识别软件~
参考这帖子
{
int[,] arr2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
int[] arr1 = GetByRank(arr2, 1);
foreach (int i in arr1)
{
Console.WriteLine(i);
}
Console.ReadKey();
}public static int[] GetByRank(int[,] arr2, int rank)
{
int[] arr1 = new int[arr2.GetLength(1)];
IntPtr hArray = Marshal.UnsafeAddrOfPinnedArrayElement(arr2, 0 * arr2.GetLength(0));
Marshal.Copy(hArray, arr1, 0, arr1.Length);
return arr1;
}
static void Main(string[] args)
{
int[,] arr2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
int[] arr1 = GetByRank(arr2, 0);
foreach (int i in arr1)
{
Console.WriteLine(i);
}
Console.ReadKey();
}public static int[] GetByRank(int[,] arr2, int rank)
{
int[] arr1 = new int[arr2.GetLength(1)];
IntPtr hArray = Marshal.UnsafeAddrOfPinnedArrayElement(arr2, rank * arr2.GetLength(0));
Marshal.Copy(hArray, arr1, 0, arr1.Length);
return arr1;
}