If someone is using the var
keyword because they don't want to "figure out the type", that is definitely the wrong reason. The var
keyword doesn't create a variable with a dynamic type, the compiler still has to know the type. As the variable always has a specific type, the type should also be evident in the code if possible.
Good reasons to use the var
keyword are for example:
- Where it's needed, i.e. to declare a reference for an anonymous type.
- Where it makes the code more readable, i.e. removing repetetive declarations.
Writing out the data type often makes the code easier to follow. It shows what data types you are using, so that you don't have to figure out the data type by first figuring out what the code does.