Eyeball Ergonomics - var for fields #4171
-
I've recently noticed that VS is recommending C# codefixes that convert code like:
into:
I wanted to pass some thoughts about this form. I don't like it because I feel as though my eyes have to jump between the first part of the line (
Is I feel like it groups the type definition and its value initialization together. Today, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The team has stated on several occasions that they are not interested in extending type inference to fields or other members. Apart from the desire to keep the contract explicitly it would also drastically change the performance characteristics of the compiler since the type of members could not be known unless the initializing expression is evaluated which could reference other members and so on. https://blogs.msdn.microsoft.com/ericlippert/2009/01/26/why-no-var-on-fields/ |
Beta Was this translation helpful? Give feedback.
The team has stated on several occasions that they are not interested in extending type inference to fields or other members. Apart from the desire to keep the contract explicitly it would also drastically change the performance characteristics of the compiler since the type of members could not be known unless the initializing expression is evaluated which could reference other members and so on.
https://blogs.msdn.microsoft.com/ericlippert/2009/01/26/why-no-var-on-fields/
dotnet/roslyn#5168
dotnet/roslyn#17 (comment)
#2996 (comment)