在 C#.net 中将对象 {double[,]} 转换为 double[,] 或 int[,]

本文关键字:double 转换 int net 对象 | 更新日期: 2023-09-27 18:33:21

我正在使用 MATLAB dll。 它接受类型为 int[,] 的矩阵作为输入,输出的类型为 :object{double[,]}

 private void pic_edges(int[,] array)
    {
        Class1  obj = new Class1();
        object res = null;
        res = obj.edge_dll(1, array, .5);
     }

名字; 价值; 类型

res ; {对象[1]} ; 对象{对象[]}
[0] ; {双[450,600]} ; 对象{双[,]}

现在我想将对象{双[,]}更改为int[,]或双[,]。 但是怎么做呢???

int[,] pic=null;
double[,] pic2=nu1l;

编辑:

我使用了以下代码:(感谢'现在不能被命名的人')

 var objectArray = obj.edge_dll(1, array, .5);
  double[,] pic3 = (double[,]) objectArray[0];

并且它转换正确。
现在如何将双 [,] 转换为整数 [,]

我使用了这段代码:(但是有更好的方法吗??

int[,] pic4 =new int[pic3.GetLength(0),pic3.GetLength(1)];
        for (var i = 0; i < pic3.GetLength(0); i++)
            for (var j = 0; j < pic3.GetLength(1); j++)
                pic4[i, j] = (int)pic3[i, j];

在 C#.net 中将对象 {double[,]} 转换为 double[,] 或 int[,]

你应该type-cast它。

如果我正确理解您的问题,您有一些东西可以从对象转换为整数数组。

尝试这样的事情:

        var objectArray  = obj.edge_dll(1, array, .5);
        for (var index = 0; index <= objectArray.Count(); index++)
        {
            anIntegerArray[index] = (int) objectArray[index];
        }