请教:
    我从Com+ 返回一个二维数组,代码如下:     .......
     object obj1 = new object();
     int success = class.method( ...., ref obj1);
     .......     obj1 就是从COM+ 返回的二维数组; 请问如何循环取得里面的值?
     我尝试过两种转换,     ArrayList al = (ArrayList) obj1;        // 这个会提示错误,不能转换;
     string[,] strArray = (string[,]) obj1;  // 这个也会提示错误;
     object[,] obj = (object[,]) obj1;       // 这个可以转换,但不懂如何循环此二维数组,     望大家指导下,thank you.
          

解决方案 »

  1.   

    object[,] detail = (object[,]) o2;
    for(int n=0; n < detail.GetLength(0); n++)
    {
    for(int m=0; m < detail.GetLength(1); m++)
               this.lbNote.Text += detail[n,m].ToString() + "<br>";
    }^_^ 搞定
      

  2.   

    不过,对于COM返回的对象,ToString()方法未必有效。
      

  3.   

    using System;public class Test {
    public static void Main() {
    Bar(); Console.WriteLine("\n\n"); Foo();
    } // &frac34;&acirc;&sup3;&Yacute;&ETH;&Iacute;&Ecirc;&yacute;×é
    public static void Foo() {
    string[][] b = new string[2][]; b[0] = new string[] {"hello", "welcome"};
    b[1] = new string[] {"ok", "haha", "wokao", "shit"}; for (int i = 0; i < b.Length; i++) {
    for (int j = 0; j < b[i].Length; j++) {
    Console.WriteLine("b[{0}][{1}] = {2}", i, j, b[i][j]);
    }
    }
    } // &para;&thorn;&Icirc;&not;&Ecirc;&yacute;×é
    public static void Bar() {
    string[,] a = new string[3, 2] {{"0_0", "0_1"}, {"1_0", "1_1"}, {"2_0", "2_1"}}; for (int i = 0; i < a.GetLength(0); i++) {
    for (int j = 0; j < a.GetLength(1); j++) {
    Console.WriteLine("a[{0}, {1}] = {2}", i, j, a[i, j]);
    }
    }
    }
    }
      

  4.   

    using System;public class Test {
    public static void Main() {
    Bar(); Console.WriteLine("\n\n"); Foo();
    } // 锯齿型数组
    public static void Foo() {
    string[][] b = new string[2][]; b[0] = new string[] {"hello", "welcome"};
    b[1] = new string[] {"ok", "haha", "wokao", "shit"}; for (int i = 0; i < b.Length; i++) {
    for (int j = 0; j < b[i].Length; j++) {
    Console.WriteLine("b[{0}][{1}] = {2}", i, j, b[i][j]);
    }
    }
    } // 二维数组
    public static void Bar() {
    string[,] a = new string[3, 2] {{"0_0", "0_1"}, {"1_0", "1_1"}, {"2_0", "2_1"}}; for (int i = 0; i < a.GetLength(0); i++) {
    for (int j = 0; j < a.GetLength(1); j++) {
    Console.WriteLine("a[{0}, {1}] = {2}", i, j, a[i, j]);
    }
    }
    }
    }
      

  5.   

    for (int i = 0; i < b.Length; i++) {
    for (int j = 0; j < b[i].Length; j++) {
    Console.WriteLine("b[{0}][{1}] = {2}", i, j, b[i][j]);
    }
    }
    这里是有问题的,因为b.Length取得是所有维度元素的总数。
    显然这会将同一元素不知道访问了多少遍。
      

  6.   

    回楼上:不是这样的。b.Length 完全相当于 b.GetLength(0)
      

  7.   

    b.Length 完全相当于 b.GetLength(0)---------------------------
    好像相当于 b.GetLength(1);
      

  8.   

    MSDN中关于Array类型的解释是:GetLength(int dimension)
    Gets a 32-bit integer that represents the number of elements in the specified dimension of the Array.[C#]
    public int GetLength(
       int dimension
    );
    dimension 
    A zero-based dimension of the Array whose length needs to be determined. A 32-bit integer that represents the number of elements in the specified dimension.//Length
    Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
      

  9.   

    b.Length 完全相当于 b.GetLength(0)---------------------------
    好像相当于 b.GetLength(1);
    --------------------------------------------------------不好意思,俺滴错了;
      

  10.   

    @ begincsdn(CNetware) Length 的含义在规则的多维数组里面的确是所有元素的定义。
    但我那个数组是个锯齿型的。
    而我现在的理解是,锯齿型数组其实是“数组的数组”,区别在于,他的每一维的定义都是一个独立的 System.Array 的实现, 所以我那样用是没错的。