When should one use dynamic keyword in c# 4.0?

ACP picture ACP · Apr 20, 2010 · Viewed 29.3k times · Source

When should one use dynamic keyword in c# 4.0?.......Any good example with dynamic keyword in c# 4.0 that explains its usage....

Answer

Amitabh picture Amitabh · Apr 20, 2010

Dynamic should be used only when not using it is painful. Like in MS Office libraries. In all other cases it should be avoided as compile type checking is beneficial. Following are the good situation of using dynamic.

  1. Calling javascript method from Silverlight.
  2. COM interop.
  3. Maybe reading Xml, Json without creating custom classes.