In the C# Coding Conventions, why does Microsoft suggest using implicit typing when the type of the variable is obvious from the right side of the assignment?
I understand it's not necessary to declare it since it is obvious but why the suggestion? Doesn't explicit typing make the code easier to follow?
var str1 = "This is clearly a string.";
vs
string str2 = "This is clearly a string.";
Is there a compile time benefits for this?
When the type of a variable is clear from the context, use var in the declaration.
From the same link. Personally it is a matter of choice, I would usestring
in your case, I usevar
for things likevar dictionary = new Dictionar<int,SomeclassObject>();
– Tritheism" "
quoted text it's obvious by sight that this is also of string type.. – ScupList<string> a = new List<string>()
. I cry if I need to declare something like thisList<Dictionary<string, List<Person>>
where explicit typing makes code harder to read. – Fulgurate