Should I *always* favour implictly typed local variables in C# 3.0?

后端 未结 12 582
梦如初夏
梦如初夏 2020-12-09 15:48

Resharper certainly thinks so, and out of the box it will nag you to convert

Dooberry dooberry = new Dooberry();

to

var doo         


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 16:25

    I have a feeling this will be one of the most popular questions asked over time on Stack Overflow. It boils down to preference. Whatever you think is more readable. I prefer var when the type is defined on the right side because it is more terse. When I'm assigning a variable from a method call, I use the explicit type declaration.

提交回复
热议问题