Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @namespace field in C# class? [duplicate]

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.)?

like image 640
Arseni Mourzenko Avatar asked May 12 '10 11:05

Arseni Mourzenko


People also ask

What is namespace explain with example?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.

Is namespace present in C?

Namespace is a feature added in C++ and is not present in C. A namespace is a declarative region that provides a scope to the identifiers (names of functions, variables or other user-defined data types) inside it.

What is the syntax for namespace?

Syntax of namespace declaration:namespace - is the keyword used to declare a namespace. namespacename - is the name given to the namespace. int m, n - are the variables in the namespace_name's scope.

What is the :: in C++?

In C++, scope resolution operator is ::. It is used for following purposes. 1) To access a global variable when there is a local variable with same name: // C++ program to show that we can access a global variable. // using scope resolution operator :: when there is a local.


2 Answers

Bascially yes. Putting a @ in front of the variable name stops an error ocurring due to that variable name being a keyword.

http://msdn.microsoft.com/en-us/library/x53a06bb(VS.71).aspx

like image 160
Jason Evans Avatar answered Sep 22 '22 15:09

Jason Evans


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

like image 29
Mike Two Avatar answered Sep 22 '22 15:09

Mike Two