Do you use "var"?

Last updated by Bryden Oliver 2 days ago.See history

In C# the "var" keyword can be used instead of providing an explicit type when declaring a variable. The type is then inferred from the initial assignment of the variable.

It is just a short hand to save developers from typing out the type of a variable.

List<string> items = new List<string>();

Figure: Bad example - You should just use "var" instead of "List"

var item = new List<string>();

Figure: Good example - Using "var" to save a few keystrokes and reduce repetition

We open source. Powered by GitHub