[英]Accessing dynamic variable value in c#.net
Can you please tell, how can I access value of my dynamic variable in C#.NET. 您能告诉我如何在C#.NET中访问动态变量的值。
dynamic response = api.createSession(order.Tables[0].Rows[i]["sessionid"].ToString(),
"description=" + description +
"&organization=" + organization +
"&allowUpload=" + allowUpload +
"&singleSignOnOnly=" + singleSignOnOnly +
"&maxUserCount=" + maxUserCount);
In above, "response" is dynamic variable and need to access its value. 在上面,“响应”是动态变量,需要访问其值。 I have tried following.. 我尝试了以下。
string[] myStringArray = new string[50];
myStringArray[0] = response[2]["Value"];
Thanks in advance.. 提前致谢..
What exactly do you mean by "its value" here? 您在这里所说的“其价值”到底是什么意思? Basically, the "value" of a dynamic
variable/field is simply a reference to an object. 基本上, dynamic
变量/字段的“值”只是对对象的引用。 What is interesting is: what does that object provide ? 有趣的是: 该对象提供了什么? Well, we can't tell you that, because we don't know what api.createSession
returns. 好吧,我们不能告诉你,因为我们不知道api.createSession
返回什么。 But it it notionally exposed, say, an Id
and a Name
- then you would just use: 但是它在概念上公开了一个Id
和一个Name
-那么您只需使用:
int id = response.Id;
string name = response.Name;
Of course, it is also possible that the object referenced by response
exposes methods, for example: 当然, response
引用的对象也可能公开方法,例如:
response.Foo();
We can't tell you. 我们不能告诉你。 And since it is dynamic
, the compiler can't tell you. 而且由于它是dynamic
,因此编译器无法告诉您。 The only thing that can tell you is the documentation of api.createSession
. 唯一可以告诉您的是api.createSession
的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.