Search code examples
c#syntaxfieldreserved-words

What is @namespace field in C# class?


I'm browsing the source code of StyleCop, and I found a curious thing:

/// <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);
}

What is this thing? Is it just a simple field where at-sign is used to indicate that it is a field, and not a namespace keyword? If so, may at-sign be used for any reserved word (for example @dynamic, @using, etc.)?


Solution

  • Yes @ sign may be put in front of reserved words to allow them to be used as variable names.

    var @dynamic = ...
    var @event = ....
    

    I actually learned that, and other things, from this question