Node is saved as draft in My Content >> Draft
-
Difference between Object Dynamic and Var in C#
Objects in c#
- Object can store any kind of value because object is a base class of all the classes in .net framework.
- Employee obj=new Employee();
- Object is not type safe
- Object can be initialize with null
- Object type can be passed as method parameter also it can return object type.
For example:
public object Method2(object param)
{
object objResponse = param;
return objResponse;
}
- Casting is required in Object
Dynamic in c#
- Dynamic type can store any kind of value.
- dynamic obj;
- Dynamic is not type safe
- Dynamic can be initialize with null
- Dynamic type can be passed as method parameter also it can return dynamic type.
See example below:
public dynamic Method(dynamic param)
{
dynamic objResponse = param;
return objResponse;
}
- Casting is not require but you need to know the property and methods related to stored type
Var in C#
- Var can store any kind of value but it is mandatory to initialize at time of declaration.
- var obj=10;
- Var is type safe
- Var cannot be initialize with null
- You cannot pass as method parameter and can not have return type as well
- Casting is not required in Var
0 Comment(s)