I am trying to learn all the new goodies that come with C# 4.0. I am failing to understand the differences between the DynamicObject
and ExpandoObject
types. It seems like DynamicObject
is used e.g. when you want to access variables from Python scripts and ExpandoObject
when talking with COM/Office objects. Am I right? What is the difference in their use?
相关问题
- How do I create a multidimensional array of object
- Save Image to file keeping aspect ratio in a WPF a
- How to detect Carriage return in a string
- How to pass in a method as a parameter?
- How to calculate the number of months between two
相关文章
- Can the “dynamic” type vary safely in a generic co
- Check if a datetime is in same week as other datet
- How do you convert any C# object to an ExpandoObje
- Adding additional attributes to each property of a
- How to test handling of AccessViolationException
- optional array Parameter in C# [duplicate]
- Visual Studio remote debugging on application star
-
Create Expression
> dynamically
Expando is a
dynamic
type to which members can be added (or removed) at runtime.dynamic
is designed to allow .NET to interoperate with types when interfacing with dynamic typing languages such as Python and JavaScript.So, if you need to handle a dynamic type: use
dynamic
and if you need to handle dynamic data such as XML or JSON: use ExpandoObjectThe declaration of an expando shows the relationship between dynamic and the expando:
And the ability to add a new property:
That last line of code creates a brand new string property in the expando object called
SomeNewStringVal
. The string type is inferred from the assignment.So an expando is a dynamic data type that can represent dynamically changing data. That's it in a nutshell. Here's a deeper look at dynamic and expando.
Complete example: