Dec. 3, 2020, 9:42 a.m.
IT | Rants

Stupid C# Language Decision

In C#, many years ago, some stupid person decided it would be a good idea to allow the use of the keyword var to define a variable without explicitly identifying its type, as type can many times be inferred from the RHS of the assignment.

So instead of defining code as in the old olden days below:

foreach (string mask in someList) {
  // Do something
}

we can now just write:

foreach (var mask in someList) {
  // Do something
}

In this case it does not make a difference but if the someList variable was a List<KeyValuePair<List<int>, IEnumerable<string>>> then this seems to make the code cleaner. Just, it does not in my wonderful IntelliJ IDEA editor that has assistive technologies:

IDEA Code Snippet
IDEA Code Snippet

It is clear that if the developers of IDEA felt the need to show the type to make the code easier to read, why introduce the var keyword in the first place? I despise var.