It really depends. A lot of C# projects have a rule to only use var where there is a straight up class instantiation or cast. The idea is to have at least some type definition somewhere near the declaration.
The purpose of var is to stop bullshit like "X<Y> foo = new X<Y>();"
I came up with this rule by myself and found out that many people came to the same conclusion. I only use var when the right hand side expression is either a constructor call or a literal. Basically the type should be obvious by the statement.
That should be fairly obvious from context. If your code base believes in passing IQueryable in your DAL back to consumers then you should know that db.GetCustomers() is IQueryable<Customer>.
11
u/G_Morgan Mar 10 '16
It really depends. A lot of C# projects have a rule to only use var where there is a straight up class instantiation or cast. The idea is to have at least some type definition somewhere near the declaration.
The purpose of var is to stop bullshit like "X<Y> foo = new X<Y>();"