Different between dynamic type variables and object type variables in C#?
Loading
Different between dynamic type variables and object type variables in C#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad Imran AnsariPosted Oct 23, 2022, 2:20 PM
Following are the some differences between Object and Dynamic types.
Object Type:
It can store any kind of value because the object is the base class of all type in .NET framework and compiler has little information about the object type.
Need to cast object variable to original type to use it and performing desired operations.
Dynamic Type:
It can store any type of the variable, similar to the old VB language variable.
It is not type safe i.e. Compiler doesn't have any information about the type of variable.
Casting is not required but you need to know the properties and methods related to stored type.
Further, you can read with example from the following link:
https://www.c-sharpcorner.com/UploadFile/rohatash/difference-between-object-and-dynamic-keyword-in-C-Sharp/