请教:
我从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.
我从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.
解决方案 »
- 请问C#中类可以作为参数传递吗?
- datagridView和comboBox刷新数据源问题
- 如何取得networkStream的全部内容?
- 机票查询软件开发求助!!
- 关于自定义类
- DataAdapter和DataSet配合是不是能对数据库进行比较方便的操作呢
- visual studio .net 2003使用问题
- 新手请教多线程问题
- 关于HttpWebRequest的一些棘手问题!!!
- c#调用API函数GetDiskFreeSpace的问题
- 在线等,马上结贴:(web) 当用鼠标 Click datagrid(web) 的某一行 怎么样触发一个事件,并获得该行的Index? 3Q !!!
- 请教关于AD用户权限的问题? 急!!!!!!
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>";
}^_^ 搞定
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]);
}
}
}
}
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]);
}
}
}
}
for (int j = 0; j < b[i].Length; j++) {
Console.WriteLine("b[{0}][{1}] = {2}", i, j, b[i][j]);
}
}
这里是有问题的,因为b.Length取得是所有维度元素的总数。
显然这会将同一元素不知道访问了多少遍。
好像相当于 b.GetLength(1);
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.
好像相当于 b.GetLength(1);
--------------------------------------------------------不好意思,俺滴错了;
但我那个数组是个锯齿型的。
而我现在的理解是,锯齿型数组其实是“数组的数组”,区别在于,他的每一维的定义都是一个独立的 System.Array 的实现, 所以我那样用是没错的。