It is mainly introduced for LINQ, when you can use an anonymous type as a projection:
var query = from person in employees where person.Salary > 10000m select new { FullName=person.Name, person.Department };
Here, the query type cannot be declared explicitly because the anonymous type does not have a name. (In real cases, an anonymous type often includes values ββfrom several objects, so there is not a single class that contains all the properties.)
It is also practically useful when you initialize a variable using a potentially long type name (usually due to generics) and simply call the constructor - this increases the density of information (reduces redundancy). There is also the amount of information in these two lines:
List<Func<string, int>> functions = new List<Func<string, int>>(); var functions = new List<Function<string, int>>();
but the second expresses it in a more compact way.
Of course, this can be abused, for example,
var nonObviousType = 999999999;
but when itβs obvious what a type variable is, I think it can significantly increase readability.
source share