What is dynamic binding in C#?

CsharpProgrammingServer Side Programming

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() {}
Updated on 20-Jun-2020 13:18:34