Resharper: vars

后端 未结 8 2121
闹比i
闹比i 2020-12-01 10:52

Why does Resharper want you to change most variables to var type instead of the actual type in the code?

8条回答
  •  感动是毒
    2020-12-01 11:27

    By default, it will "green squiggle" declarations of this type :

    Person p = new Person();
    ^^^^^^
    

    Because of the repetition.

    It will also suggest (small green underscore) var when it can be inferred :

    Person p = repository.GetPerson(1);
    ¯¯¯
    

    In this case it can be infered because of the return type of the GetPerson method.

    As stated by Jon Skeet, you can disable these suggestions in resharper's options.

提交回复
热议问题