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.)?
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.
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With