2013-10-01 3 views
0

나는 MATLAB dll을 사용하고 있습니다. 입력으로 int [,] 유형의 행렬을 취하고 출력은 다음 형식입니다. object {double [,]}{double [,]}을 double [,] 또는 int [,]로 변환 C# .net

private void pic_edges(int[,] array) 
    { 

     Class1 obj = new Class1(); 
     object res = null; 
     res = obj.edge_dll(1, array, .5); 
    } 

이름; 가치; 타입

res; {object [1]}; object {object []}
[0]; {double [450,600]}; 객체 {double [,]}

이제 개체 {double [,]}을 int [,] 또는 double [,]로 변경하고 싶습니다. 그러나 어떻게 ???

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

편집 :

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

를 ('지금 그는 이름해서는 안 사람'덕분에)하고 올바르게 변환 :

는 다음 코드를 사용했다.
지금 이중 변환하는 방법 [,] 나는이 코드를 사용

[,] int로 (하지만 거기에 어떤 좋은 방법 ??입니다)

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]; 

답변

1

당신이해야 type-cast 그것.

질문을 올바르게 이해하면 개체를 정수 배열로 변환해야합니다. 이 같은

시도 뭔가 :

 var objectArray = obj.edge_dll(1, array, .5); 

     for (var index = 0; index <= objectArray.Count(); index++) 
     { 
      anIntegerArray[index] = (int) objectArray[index]; 
     } 
+0

@majidmobini는 : 대답 업데이트! –

+0

그것은 말한다 : 'objectArray [0]'을 'int'로 unbox 할 수 없다. –

+0

즉, objectArray [0]은 정수가 아니다. obj.edge_dll() 메서드의 서명을 정확하게 알려줄 수 있습니까? 그것은 무엇을 반환합니까? [객체 배열을 반환하면 위의 코드가 작동합니다.] –

관련 문제