View Single Post
  #4 (permalink)  
Old December 2nd, 2010, 09:52 AM
DrPurdum DrPurdum is offline
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default @ Operator

First, you're right. The "@" operator is the "at" sign while the "&" is the amperand.

As to your code, while your statement:

int @int = 1;

is legal, it's a really bad idea to use a keyword as the basis for a variable name, especially when using a legal operator as the first letter for the name. (Indeed, I think it should be an error to use the @ in this manner.) If you want to reflect the idea that you're using an integer, I would change this to:

int myInteger = 1;

or something like that. Even better would be a name that reflects the purpose of the variable.

The string literal operator (@) would have no effect on the variable you defined above since it only appears on the left side of the assignment operator. In that case, it is simply viewed as another "letter" in the identifier's name (e.g., @int). This means it is used in the expression in such a way that the compiler does not interpret it as operator.

In the case of the first statement:

string strVerbatim = @"C:\Temp";

the compiler sees the operator on the righthand side of the assignment expression and says: "Aha! The backslash is a literal and means I should NOT interpret the "\T" as the tab character."

Finally, the @buff used as the argument to DriveInfo() causes the compiler to alter the attribute list for buff in the symbol table to accept any string data as a string literal. Remember that arguments passed to a method are passed on the stack and "popped" off into a temporary variable in the method. (Reference variables pop the lvalue instead of the rvalue.) This means that the method arguments are "assigned" to the temporary variables created by the method. Therefore, the @buff argument can be viewed as executing the statement:

string strTemp = @buff;

inside the DriveInfo() method.

I hope this helps.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)