Dynamic Keyword in CsharpThe dynamic type was introduced in C# 4.0.
It can able to store any type of the variable.
Dynamic type can be passed as function argument and function also can return object type.
The dynamic type uses System.Object indirectly but it does not require explicit type casting for any operation at runtime, because it identifies the types at runtime only.
namespace Dynamic
{
class Program
{
public void DynamicCheck()
{
dynamic logic = 1001;
logic = 1001 + 1000;
Console.WriteLine("Check the dynamic variable value:{0}",logic);
logic = "DotnetLogix";
Console.WriteLine("Check the dynamic variable value:{0}", logic);
Console.ReadLine();
}
static void Main(string[] args)
{
Program prog = new Program();
prog.DynamicCheck();
}
}
}
The output will be like the below image: