User Id :    Password :      New Member   Forgot Password  
 
Dynamic Keyword in Csharp
Description Dynamic Keyword in Csharp   No. of Views     1306
  Rating     0
Author Gaurav   Posted On     09 Feb 2014
Tags C# 4.0,ASP.NET 4.0    

Sample Code   Download Code

The 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:
 

 

About Author

About Author I am as simple as c#. Gaurav
No Photo
 
Country India
Company N/A
Home Page N/A

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code