举例说明:多维数组 int a[2,3];
我要使用a的第1行,应该怎么办?数组的数组 int a[2][3]
我要使用foreach,应该怎么办?

解决方案 »

  1.   

    foreach(int[] in aa)
    {
    }
    a[0][]
      

  2.   

    多维数组 int a[2,3]; C#中二维数组我要使用a的第1行,应该怎么办? foreach语句和多维数组
      

  3.   

    for (int i = 0; i < a.GetLength(0); i++)
    {
       if (a[i, 0] != null)
       {
        ....
       }
    }
    a.GetLength(0)= 2;
    a.GetLength(1)= 3;
    具体你应该知道怎么做了吧!
      

  4.   

    http://msdn.microsoft.com/zh-cn/library/2yd9wwz4(VS.80).aspx
    http://msdn.microsoft.com/zh-cn/library/2s05feca(VS.80).aspx
      

  5.   

    这不是C++……你定义了几维数组,就当成几维用。至于取第一行,那么就a[0,i]如果你想foreach,就一行一行地foreach。
      

  6.   

    class ArrayTest
    {
        static void Main()
        {
            // Declare the array of two elements:
            int[][] arr = new int[2][];        // Initialize the elements:
            arr[0] = new int[5] { 1, 3, 5, 7, 9 };
            arr[1] = new int[4] { 2, 4, 6, 8 };        // Display the array elements:
            for (int i = 0; i < arr.Length; i++)
            {
                System.Console.Write("Element({0}): ", i);            for (int j = 0; j < arr[i].Length; j++)
                {
                    System.Console.Write("{0}{1}", arr[i][j], j == (arr[i].Length - 1) ? "" : " ");
                }
                System.Console.WriteLine();
            }
        }
    }
      

  7.   

    for (int i = 0; i < a.GetLength(0); i++) 

      if (a[i, 0] != null) 
      { 
        .... 
      } 

    a.GetLength(0)= 2; 
    a.GetLength(1)= 3; 
    具体你应该知道怎么做了吧! 
      

  8.   

    多维数组 int a[2,3]; 
    我要使用a的第1行,应该怎么办? 
    for(int i=0;i<1;i++)
    {
     for(int j =0;j<3;j++)
     {
      Console.WriteLine(a[i,j].ToString());
     }
    }数组的数组 int a[2][3] 
    我要使用foreach,应该怎么办?foreach(int[] aa in a)
    {
      foreach(int aa1 in aa)
      {
        Console.WriteLine(aa1.ToString());
      }
    }
      

  9.   

    嗯第一个问题,其实是想问
    我要
    a[2,3]的
    a[0,0],a[0,1],a[0,2]
    一定要循环每个都取出来?
    而不能用诸如a[0]就把这行选出来了。第二个问题其实是觉得这个用法很烦。
      

  10.   


    1、必须的,这不是C++,所以这是必须的。
    2、麻烦的,这不是C++,所以这是麻烦的。谁让你用C#来着。
    你可能是想比较一下int[,]和int[][]哪个好用罢了……
    矩形阵就用前者,邻接阵就用后者……想用C#就不要去考虑“技巧”,那是给C++和汇编程序员考虑的。C#的灵活可不是在这上面,C#的语言模型是设计模式,不是二进制……