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

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

问题描述

我发现,您可以在C#中的@字符开始你的变量名。
在我的C#项目,我用一个Web服务(我添加Web引用我的项目),这是用Java编写的。一位在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#语言规范 §2.4.2标识符(C#)

在preFIX@允许使用
  关键字作为标识符,这是
  与其他连接时非常有用
  编程语言。人物 @
  实际上不是的部分
  标识符,所以该标识符可能是
  在其他语言视为正常
  标识符,而不preFIX。一个
  与@ preFIX标识符称为
  逐字标识符。

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天全站免登陆