Advantages of using const instead of variables inside methods

后端 未结 8 928
北恋
北恋 2020-12-02 16:09

Whenever I have local variables in a method, ReSharper suggests to convert them to constants:

// instead of this:
var s = \"some string\";
var flags = Bindin         


        
8条回答
  •  隐瞒了意图╮
    2020-12-02 17:07

    The const keyword tells the compiler that it can be fully evaluated at compile time. There is a performance & memory advantage to this, but it is small.

提交回复
热议问题