Using “value” as an identifier in C#

后端 未结 6 487
感动是毒
感动是毒 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条回答
  •  Happy的楠姐
    2021-01-03 20:45

    In a property setter, the variable name value is reserved. It is used as the name of the variable which can be assigned to a backing field.

    The question: Is it always safe to use "value" as a variable name outside of a property setter? If not, when can this be done safely? And, is this considered bad practice?

    It's only reserved in the property setter. It's a very generic name, but it can often be the best description of the variable you are working with.

    MSDN info

提交回复
热议问题