Why declare a variable as type var vs the actual type?

Why was the variable declared using var instead of the actual variable type in ManageState? Is this effeciency or something? I’ve always been taught to clearly specify the variable type, which increases readabilty?

private void ManageState()
{
    var nextStates = state.GetNextStates();

Hi,

It’s a matter of personal preference, and there have been discussions on the internet for years. One argument is that the var keyword would make the code more readable.

As for me, I disagree with that claim and prefer the explicite type declaration. However, I don’t mind if students use the var keyword. Use what you prefer. :slight_smile:

Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms