如何获取对象并将其转换为结构和副签证?
public void myMethod1(object myInputObject, out string myOutputString)
{
myInputObject = null;
myOutputString = "";
//Convert object into a struct, then do something
}
答案 0 :(得分:0)
定义结构并在方法中设置字段值。
答案 1 :(得分:-1)
我想你想要这样的东西:(伪代码)
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