简体   繁体   English

是否可以通过索引访问Expandoobject属性?

[英]Is it possible to access Expandoobject properties by index?

It is possible to override the TryGetIndex method of a dynamic object to access the dynamic object properties by index however I am dealing with an Expandoobject (of the System.dynamic namespace ) which you can't inherit from. 可以重写动态对象的TryGetIndex方法以通过索引访问动态对象属性,但是我正在处理您不能继承的Expandoobject( System.dynamic命名空间 )。 Is there a way around this? 有没有解决的办法? Thanks 谢谢

ExpandoObject is nothing but a fancy IDictionary which leverages the DLR. ExpandoObject不过是利用DLR的精美IDictionary

There is no way you can access a IDictionary<TKey,TValue> via index. 您无法通过索引访问IDictionary<TKey,TValue> You may find ElementAt method of linq useful, but it is not. 您可能会发现linq的ElementAt方法很有用,但没有用。 There is no ordering in dictionary, You can read more about hashtable datastructure (Dictionary is also a hashtable). 字典中没有排序,您可以阅读有关散列表数据结构的更多信息(词典也是散列表)。

For accessing dictionary via index you may use OrderedDictionary . 为了通过索引访问字典,您可以使用OrderedDictionary One disadvantage is that is is not generic. 一个缺点是不是通用的。

Know more about issues when accessing elements via index from a Dictionary 通过字典从索引访问元素时了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM