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(); } } }
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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.
dynamic
Dynamic is a type of declaration This means the type of variable declared is decided by the compiler at runtime time.
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.