2011-04-11 2 views
1

개체를 가져 와서 구조 및 비자로 변환하려면 어떻게해야합니까?개체 -> 구조체?

public void myMethod1(object myInputObject, out string myOutputString) 
{ 
    myInputObject = null; 
    myOutputString = ""; 

    //Convert object into a struct, then do something 
} 
+8

당신이 "구조체로 개체를 변환"이란 무엇을 의미합니까? 어떤 물건? 실제로 boxed 값을 제공하는 경우 무언가를 unbox 할 수 있지만 이전 참조 유형에서 구조체를 만들 수는 없습니다. 당신이하려는 일은 정말로 명확하지 않습니다. –

+2

권투에 대해 말하기/unboxig? http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx –

답변

0

난 당신이 이런 일을한다고 가정 : (의사 코드)

class myclass 
{ 
public int a; 
public float b; 

} 

struct somestruct 
{ 

somestruct(int a, float b) 
{ 
    this.a = a; 
    this.b = b; 
} 

int a; 
float b; 

} 


myclass mc = new myclass(); 

mc.a = 125; 
mc.b = 12.5; 

somestruct s = new somestruct(mc.a, mc.b); //all fields of mc are now in struct somestruct 
0

메서드 내에서 구조체를 정의하고 필드 값을 설정하십시오.

관련 문제