Practice mode C#

How does dynamic differ from var in C#?

Correct answer B. dynamic defers member binding and type checking to run time, while var is resolved at compile time

Explanation

With dynamic, the compiler skips checking member access, so calling a misspelt method compiles but throws RuntimeBinderException when executed. var is purely compile-time inference and keeps full static checking. dynamic is useful for COM interop, dynamic languages and JSON-like objects, but it is slower because binding happens at run time and you lose IntelliSense and compile-time errors.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.