Tool to refactor C# var to explicit type

前端 未结 7 656
陌清茗
陌清茗 2020-12-03 17:15

Our coding standards ask that we minimise the use of C# var (suggests limiting it\'s use to being in conjunction with Linq). However there are times when using generics wher

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 17:34

    I've got ReSharper 4.1, and it does offer this option (in either direction).

    Actually, I'd recommend challenging the standard... the former is far more readable than the latter (especially if you call the variable pair or something similar). I would't use "var" for var i = 0, but it is ideally suited to the above.

    For bulk changing, go to:

    • Cleanup Code... (pick a profile => "Edit Profiles" => Tools => Code Cleanup)
      • C#
        • Use 'var' in declaration
          • Replace direction = Can 'var' to type usage
          • 'foreach' iterator declaration style = Always use explicit type
          • Local variable declaration style = Always use explicit type

    and run...

提交回复
热议问题