开发者

how to escape key words in c#?

I want to do the equivalent of the following VB in c#

Function([class]) "hello"

This would be the same as this in c#

class=>"hello"

The problem is that the wor开发者_如何学运维d class is a key word in the language. But I want to use it as a variable name. In the VB example you can use the [] brackets to 'escape' that key word and allow it to be used as a variable name.

Is there a way to do this in C# ?


You need to add @ to variable names:

@class

But it is a very bad practice. Every time you name your variable as a keyword a kitten dies :)


Use @ for reserved words:

@class=>"hello"


You can prefix any keyword with a @.

But I don't think it's a recommended practice, and code analysis complains about it for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜