3
Reply

What is difference between object, var and Dynamic?

Khushbu Desai

Khushbu Desai

Oct 07, 2017
1.4k
1

    Everything in .net is derived from System.Object type.Difference between Object and dynamic. 1.You cannot implicitly cast a variable of type Object into any other type. Compiler will not let you do that. On the other hand you can implicitly cast any type to dynamic. Compiler will not complain because casting will be performed during run time and exception, if required will raised during run time. 2.Because dynamic is same as object, You cannot write overloaded methods which differ in Object and dynamic in arguments.Difference between dynamic and var. 1.Declaring a local variable as dynamic or var has only syntactical difference. 2. You cannot declare a variable of type var without initializing it, But you can do that for a dynamic variable 3. You cannot use a var variable to pass as method argument or return from a method. 4. You cannot a cast an expression to var but you can do it for a dynamic variable.

    Tushar Dikshit
    November 06, 2017
    0

    Object is instance of class Var is variable Dynamic means run time changes

    Neha Kumari
    November 05, 2017
    0

    Object is a base type in .NET. All others types are inherit from it. Var is not a type, but the instruction for the compiler to conclude a variable type from the program context. Dynamic – is a special type for which the compiler don't do type checking at compile time.

    Khushbu Desai
    October 07, 2017
    0