开发者

Object --> Struct?

How do I take an Object and convert it into a struct and vice visa?

public void myMethod1(object myInputObject, out st开发者_运维问答ring myOutputString) 
{
   myInputObject = null;
   myOutputString = "";

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


Define a struct and set fields values inside your method.


I suppose you want something like this: (pseudo code)

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜