Dynamic Binding in C#

CsharpProgrammingServer Side Programming

In Dynamic binding, the compiler will not do type checking at compile time. At run time, 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.

Example

public dynamic GetAnonymousType() {
   return new {
      StudentName = "Tom",
      Subject = "Java",
   };
}

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

public dynamic GetAnonymousType() {
}
raja
Published on 17-Sep-2018 16:50:13
Advertisements