如何在C#中转义关键字? [英] how to escape key words in c#?

查看:130
本文介绍了如何在C#中转义关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#中做以下VB的等效操作

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

Function([class]) "hello"

与c#中的相同

class=>"hello"

问题在于,单词class是该语言中的关键字.但我想将其用作变量名.在VB示例中,您可以使用[]方括号转义"该关键字并将其用作变量名.

The problem is that the word 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.

在C#中有没有办法做到这一点?

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 :)

这篇关于如何在C#中转义关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆