获得动态变量的价值 [英] getting value of dynamic variable

查看:77
本文介绍了获得动态变量的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我从动态变量重新获取值时出现问题


我有一个类型为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆