What are the differences between Dynamic Var and an Object in C#?

If you declare a variable as being of type Object, you're not going to be able to call any methods on that object other than the ones defined in the Object class (or pass it as an argument to any method that takes something other than Object as their argument) unless you use a cast.

If you use var the type of the variable is going to be the (static) type of the assigned expression. So you'll be able to call any methods on it that are defined on that type and give it as an argument to any method that takes arguments of that type.

If you use dynamic, you'll be able to call any method on it and pass it as an argument to any method without any type checking happening at compile time. If the types are not compatible, you'll get an exception at runtime.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.