C# Dynamic BindingC# dynamic is a keyword that is used to make a property or a method dynamic. When we make dynamic type, compiler does not check it at compile-time. Compiler checks it only at run time. The purpose of using dynamic binding is to avoid compile time checking of the code. The property created using dynamic keyword works like object. Dynamic variables are compiled into type object variables and exist only at compile time, not at run time. The type of dynamic and object both are similar. We can check it by using the following code. C# Dynamic Binding Example 1Output System.Int32 System.Int32 Now, let's manipulate the both objects and see the working difference. C# Dynamic Example 2Now, it produces a compile-time error due to object v1. The dynamic object does not check at compile time so, it does not produce any error at compiler-time. Output DynamicExample.cs(13,18): error CS0019: Operator '+' cannot be applied to operands of type 'object' and 'int' Dynamic Properties and MethodsIn the following example, we are creating dynamic properties and methods. C# Dynamic Binding ExampleOutput Peter Welcome to the javatpoint Next TopicC# Named and Optional Arguments |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India