What is dynamic binding in C#?


In Dynamic binding, the compiler will not do type checking at compile time. At runtime, the checking is done.

Use it to avoid the restriction of anonymous types to one method. This is only because the type name is visible only to the compiler; therefore, you cannot declare it as the return value of a method.

Let us see an example −

public dynamic GetAnonymousType() {
   return new {
      StudentName = "Jack",
      Subject = "Maths",
   };
}

Above, the method is set to be dynamic, that would mean the compiler won’t do type checking at compile time −

public dynamic GetAnonymousType() {}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jun-2020

352 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements