C# 变量名中@ 字符的用途/含义是什么? [英] What's the use/meaning of the @ character in variable names in C#?

查看:37
本文介绍了C# 变量名中@ 字符的用途/含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现您可以在 C# 中以@"字符开头变量名.在我的 C# 项目中,我使用了一个用 Java 编写的 Web 服务(我向我的项目添加了一个 Web 引用).WSDL 中定义的接口对象之一具有名为params"的成员变量.显然,这是 C# 中的保留字,因此您不能拥有具有名称为params"的成员变量的类.生成的代理对象包含一个如下所示的属性:

I discovered that you can start your variable name with a '@' character in C#. In my C# project I was using a web service (I added a web reference to my project) that was written in Java. One of the interface objects defined in the WSDL had a member variable with the name "params". Obviously this is a reserved word in C# so you can't have a class with a member variable with the name "params". The proxy object that was generated contained a property that looked like this:

public ArrayList @params {
    get { return this.paramsField; }
    set { this.paramsField = value; }
}

我搜索了 VS 2008 c# 文档,但找不到任何相关信息.搜索谷歌也没有给我任何有用的答案.那么变量/属性名称中@"字符的确切含义或用法是什么?

I searched through the VS 2008 c# documentation but couldn't find anything about it. Also searching Google didn't give me any useful answers. So what is the exact meaning or use of the '@' character in a variable/property name?

推荐答案

直接来自 C# 语言规范标识符 (C#):

前缀@"允许使用关键字作为标识符,即与其他人交互时很有用编程语言.人物 @实际上不是标识符,所以标识符可能是在其他语言中被视为正常标识符,不带前缀.一个带有@前缀的标识符被称为逐字标识符.

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

这篇关于C# 变量名中@ 字符的用途/含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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