conveniently shoot yourself in the foot
Feb. 4th, 2010 09:30 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
(10x
109)
Here is where the new dynamic keyword in C# 4.0 comes in. It tells the compiler not to enforce additional rules upon your code.
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
Here is where the new dynamic keyword in C# 4.0 comes in. It tells the compiler not to enforce additional rules upon your code.
dynamic dyn = 10;
Console.WriteLine(dyn.GetType());
// Same as "object".
// Prints System.Int32 because
// this is the type of the value stored in this object.
// No compiler error, because
// the compiler does not try to identify
// the type of the dynamic object at compile time.
dyn = dyn + 10;
// Also, this operation will succeed for all numeric
// or other types that support a “+” operation.
dyn = 10.0;
dyn = dyn + 10;
dyn = "10";
dyn = dyn + 10;