How do I access an anonymous object's properties outside its scope?

前端 未结 4 969
终归单人心
终归单人心 2021-01-25 19:08

Scope might not be the right word. With the following code I can\'t get access to the collections element\'s object\'s properties. Is there a better return data type or a way t

4条回答
  •  抹茶落季
    2021-01-25 19:39

    Once you leave the scope in which the anonymous type was defined, you have to use reflection to get to its members.

    The two other options I can think of are to use a dynamic type (if using 4.0 framework or later) or to create a defined type instead of an anonymous type.

提交回复
热议问题