获得动态变量的价值 [英] getting value of dynamic variable
问题描述
你好,我从动态变量重新获取值时出现问题
我有一个类型为Class的动态变量,它有像Name,Age等属性
所以如何获得价值 动态d = classObject
d.Age访问这些行时我收到错误
下一个示例有效:
class
MyClass
< p style ="margin-bottom:0cm; margin-bottom:.0001pt; line-height:normal; text-autospace:none">
{
public
int < span style ="font-size:9.5pt; font-family:Consolas; color:black">年龄{
get ;
set ; }
}
。 。 。
var c =
new MyClass();
c.Age = 101;
动态d = c;
int 年龄= d.Age;
Console.WriteLine(年龄);
还添加对"Microsoft.CSharp"的引用"。
显示错误。
&NBSP; 跨度>
hello, I am getting a problem while reteriving a value from dynamic variable
I have a dynamic variable of type Class it is having Properties like Name,Age etc
so how to get the value dynamic d= classObject
d.Age while Accessing these line I am getting Error
The next example works:
class MyClass
{
public int Age { get; set; }
}
. . .
var c = new MyClass();
c.Age = 101;
dynamic d = c;
int age = d.Age;
Console.WriteLine( age );
Also add a reference to "Microsoft.CSharp".
Show your errors.
这篇关于获得动态变量的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!