dynamic keyword in CSharp

Many of us like static type checking in C# because compiler can find early. But static type checking does for strict the way of write some code .You have to have type definition and metadata available at compile time in order to get work done. Before C# 4.0 it is impossible to interact with the dynamic languages such as Ruby and Python . There are also difficult in some scenarios like to work with COM objects. Anyone who trying to interop from C# code to legacy code In COM often pain . Perhaps you have felt some issues while interacting with Microsoft Office COM components to automate Word or Excel. In C# 4.0 Microsoft introduces a new keyword called dynamic. A dynamic variable is a statically typed variable is a dynamic variable. When C# compiler see the dynamically typed variable it turns off compile time check. Any operation to perform on a dynamic object reference by that variable like calling a method , setting up a property all will resolve at runtime.
dynamic person=new Person();
person.Name=”Jameel”;

Why Dynamic Language Runtime in CSharp?

Introduction

In .Net 4.0 Microsoft built a new runtime on the top of CLR for supporting the dynamic programming languages. This new runtime is the DLR(Dynamic Language Runtime) , not only does the DLR allows the dynamic languages  like Ruby and Python to execute code on .net runtime but also allows statically types languages c# to pick up some dynamic language features.

Why Dynamic?

Computer science generally divides languages in two categories. We have dynamic languages (Javascript, Ruby, Python, PHP, and Perl) and we have static languages (C#, F#, Java, Haskell, C,C++). One thing keep in mind that the distinction to often blurred and fuzzy because some languages like C# have features that follows both categories .A dynamic generally is a language allow you to modify the code  and modify the types in the runtime. Dynamic languages like JavaScript, Ruby, and Python they do not have a traditional compiler or compilation face so they do not perform type checking until the program runs.If they perform type checking at all many dynamic languages automatically converts types at runtime to keep an application running. C# is the language on the other hand is a static language even they are talking about dynamic features of C#.It is traditionally a static language because all of the common idioms and patterns for C# revolve around the languages static features, we have the compiler, static type checking at compile time so the compiler will raise an error try to assign a string to an integer variable. Also in C# I can define a class with the property of type string
public class Customer
{
public string Name{get;set;}
}

One time when the compiler creating an assembly with these class definition every object I create using this class will have a property of type string. There is now way to change the objects to remove that property and add a new property without changing the definition in the source code in recompiling. The classes in the dynamic languages such as Ruby I can able to change objects instantiated from the class definition also I could remove properties and methods or add properties and methods. In fact most class based dynamic languages  will also be change definition of the class at runtime without recompiling and then all new objects created from the class definition will have the changes made dynamically.

Continuation Article 1 : dynamic keyword in C#