我有一个匿名类型变量。这个变量是从另一个函数中获取的,我们无法更改它。
// var a {property1 = "abc"; property2 = "def"}
我有一个类:
class Myclass{
string property1;
string property2;
}
如何将变量 a 转换为 Myclass 类型。我尝试过:
Myclass b = (Myclass)a;
但是它不起作用。
如果我初始化:
Myclass b = new Myclass{
property1 = a.property1,
property2 = a.property2,
}
它正在工作,但是需要很多代码,因为MyClass
有很多属性。
有人能帮我吗?感谢任何答案。