57- C# the difference between object, dynamic and var

preview_player
Показать описание
Object:
Each object in C# is derived from object type, either directly or indirectly. It is compile time variable and require boxing and unboxing for conversion and it makes it slow. You can change value type to reference type and vice versa.
Var:
It is compile time variable and does not require boxing and unboxing. Since Var is a compile time feature, all type checking is done at compile time only. Once Var has been initialized, you can't change type stored in it.
Dynamic:
It is run time variable and not require boxing and unboxing. You can assign and value to dynamic and also can change value type stored in it. All errors on dynamic can be discovered at run time only. We can also say that dynamic is a run time object which can hold any type of data.
Рекомендации по теме