当前位置:编程学习 > C#/ASP.NET >>

c# 矩阵列对换

有个数组 int [,]a ={{1,2,3},{4,5,6}{7,8,9}{10,11,12}{13,14,15}{16,17,18}}
要求将第一与第二列互换,第三列不变,希望高手能教教我,给出源码,急急急啊
--------------------编程问答--------------------

int[,] a =
{
   { 1, 2, 3 }, 
   { 4, 5, 6 },
   { 7, 8, 9 },
   { 10, 11, 12 },
   { 13, 14, 15 }, 
   { 16, 17, 18 }
};

for (int i = 0; i < a.GetLength(0); i++)
{
    int v = a[i, 0];
    a[i, 0] = a[i, 1];
    a[i, 1] = v;
}

for (int i = 0; i < a.GetLength(0); i++)
{
    Console.WriteLine("{0,10}{1,10}{2,10}",
        a[i, 0], a[i, 1], a[i, 2]);
}
--------------------编程问答--------------------
引用 1 楼 qqamoon 的回复:
C# code

int[,] a =
{
   { 1, 2, 3 }, 
   { 4, 5, 6 },
   { 7, 8, 9 },
   { 10, 11, 12 },
   { 13, 14, 15 }, 
   { 16, 17, 18 }
};

for (int i = 0; i < a.GetLength(0); i++)
{
    int v = a[i, 0];
  ……


++ --------------------编程问答-------------------- for (int j = 0; j < ary.GetLength(1); j++)
  {
     x=ary[0, j];
     ary[0, j]=ary[1, j];
  }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,