How do I use a C# reserved keyword as a property name without the @ prefix?

后端 未结 3 944
旧时难觅i
旧时难觅i 2020-12-20 15:59

I need to design a class where one property name has to be return, but when I create a property name like return then I get an error.

Afte

3条回答
  •  粉色の甜心
    2020-12-20 16:15

    You can't. It is a reserved keyword. That means "you can't". Contrast to "contextual keywords" which usually means "we added this later, so we needed it to work in some pre-existing scenarios".

    The moderate answer here is: use @return.

    A better answer here is: rename your property. Perhaps ReturnValue.

    There is also the option of, say, Return - but you might need to think about case-insensitive languages too.

提交回复
热议问题