what is different Var And Dynamic Types In c#.

Total Post:341

Points:2389
C#  .NET 
C#
 740  View(s)
Ratings:
Rate this:
I want to know what is different Var And Dynamic Types In c#. give me a sample example 
  1. Post:13

    Points:91
    Re: what is different Var And Dynamic Types In c#.

    Var is a type of declaration which is resolved at compile time that means compiler takes care of the type which is declared as var. The var keyword is used to declare the var type.


    Dynamic is also a type of declaration which is decided at Run time. It means to say that if you declare a type of variable then compiler will check it on the Rum Time only. The dynamic keyword is used to declare dynamic type.
    As you know it will check at rum time, so there is no need to initialize the value at compile time, you can initialize it on run time. 

      Modified On Jan-24-2016 10:48:10 PM
  1. Post:281

    Points:2003
    Re: what is different Var And Dynamic Types In c#.

    Var

     Var keyword is an implicit way of defining DataTypes. Implicit means indirect way of defining variable types.
    In simple words var keyword  data types is defined by the compiler during the generation of the “IL” code.

    using System;
    namespace ConsoleDemo

        public class Program
        {
            public static void Main(string[] args)
            {     

               var name = "Pass string data type ";
                name = 45545454;
                Console.WriteLine("The value of name is " + name);
                Console.ReadLine();
            }
        }
    }

     

    dynamic

    Dynamic is a type of declaration This means the type of variable declared is decided by the compiler at runtime time.

     

    using System;
    namespace ConsoleDemo

        public class Program
        {
            public static void Main(string[] args)
            {

                dynamic data = "Pass string data type ";
                data = 88582045785;
                Console.WriteLine("The value of data is " + data);
                Console.ReadLine();
            }
        }
    }

     

     


     

     

      Modified On Jan-24-2016 11:00:53 PM

Answer