Var Keyword: All the methods, property or any other information are available at compile time.
Dynamic Keyword: As the name suggest all the method, property and other information is available at run time.
Let's understand it with a example.
- class Employee
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public int Salary { get; set; }
- }
- var employee=new Employee(){ Id=1, Name="Diwakar", Salary=6000 } ;
- Console.WriteLine("Employee First Name:"+employee.Name);
- Console.WriteLine("Employee Last Name:"+employee.Last);
- dynamic employee = new Employee() { Id = 1, Name = "Diwakar", Salary = 6000 };
- Console.WriteLine("Employee Name:"+employee.Name);
- Console.WriteLine("Employee Last Name:"+employee.Last);