Skip to content
Discussion options

You must be logged in to vote

Today, var works for variables. Can it be expanded to work with fields too?

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)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@alrz
Comment options

@CyrusNajmabadi
Comment options

@alrz
Comment options

Answer selected by svick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants