Using “value” as an identifier in C#

后端 未结 6 485
感动是毒
感动是毒 2021-01-03 20:02

In writing short helper functions, I often find myself wanting to use the variable identifier \"value\" as an argument. It seems as though Visual Studio compiles this just f

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 20:41

    As other have answered value is reserved for properties, however value it is not reserved specifically for methods, therefore, you can use value for variables everywhere other then properties setter

    However if you set value in the get it will work just fine.

    Good

    public int MyProperty { get { int value = 0; return value; }}
    

    Not good

    public int MyProperty { get { ... } set { int value = 0; _MyProperty = value }}
    

提交回复
热议问题