我正在浏览the source code of StyleCop,我发现了一件奇怪的事情:
/// <summary>
/// The namespace that the rule is contained within.
/// </summary>
private string @namespace;
// [...]
internal Rule(string name, string @namespace, string checkId, string context, bool warning) : this(name, @namespace, checkId, context, warning, string.Empty, null, true, false)
{
Param.Ignore(name, @namespace, checkId, context, warning);
}这是什么东西?它只是一个简单的字段,其中at-sign用于指示它是一个字段,而不是一个namespace关键字?如果是这样,at-sign是否可以用于任何保留字(例如@dynamic、@using等)?
发布于 2010-05-12 19:25:51
Yes @符号可以放在保留字的前面,以允许它们用作变量名。
var @dynamic = ...
var @event = ....我实际上从this question那里学到了这一点,以及其他一些东西
发布于 2010-05-12 19:25:54
基本上是这样的。在变量名前面加上@可以避免由于变量名是关键字而导致的错误。
http://msdn.microsoft.com/en-us/library/x53a06bb(VS.71).aspx
发布于 2010-05-12 19:26:40
可以,您可以使用@作为变量的first and only first字符。
https://stackoverflow.com/questions/2818281
复制相似问题