I don't quite get what it's going to let me do (or get away with :)
It is used to avoid the compile-time type checking. The compiler does not check the type of the dynamic type variable at compile time, instead of this, the compiler gets the type at the run time. The dynamic type variable is created using dynamic keyword.
Programming languages are sometimes divided into statically typed and dynamically typed languages. C# and Java are often considered examples of statically typed languages, while Python, Ruby and JavaScript are examples of dynamically typed languages.
The two big areas are:
Other uses include things like:
In C# itself, this allows a few things, such as a basic approach to generic operators:
static T Add<T>(T arg1, T arg2) { // doesn't work in CTP
return ((dynamic)arg1) + ((dynamic)arg2);
}
(of course, I'd argue that this is a better (more efficient) answer to this)
From Charlie Calvert's blog:
Useful Scenarios
There are three primary scenarios that will be enabled by the new support for dynamic lookup:
- Office automation and other COM Interop scenarios
- Consuming types written in dynamic languages
- Enhanced support for reflection
Read more here: http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With