Practice mode C#

Which statement about the var keyword in C# is true?

Correct answer B. The type is inferred at compile time and the variable stays strongly typed

Explanation

var asks the compiler to infer the variable's type from its initialiser, so var n = 10; makes n an int for good; assigning a string later is a compile error. It is only allowed for local variables and needs an initialiser. Behaviour that defers type checks to run time belongs to dynamic, not var, and fields must declare their type explicitly.

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.