With the @ symbol we can display any string without using the escape characters inside the string. For example, instead of writing the following statement:
string myDoc = “C:\\Documents\\Letters\\friends.doc”;
we can precede the string with the @ symbol, like this:
string myDoc = @”C:\Documents\Letters\friends.doc”;
Both methods declare a string that contains the string “C:\Documents\Letters\friends.doc”
In fact, anything inside the quotation marks is displayed as is. For example:
string myString = @”Dear Sir,
I have read your manuscript ‘Learn C# in three Day’s, and I would like to inform you that we are interested in publishing the book.
Yours,
Dylan A. Combel”;
If we display this string we get the following:
Dear Sir,
I have read your manuscript ‘Learn C# in three Day’s, and I would like to inform you that we are interested in publishing the book.
Yours,
Dylan A. Combel
In order to display a quotation mark inside the text, use two quotation marks instead of one. For example:
@”He said, “”You should stop by when you can,”” OK?”
This string is displayed like this:
He said, “You should stop by when you can,” OK?
The last use of the @ symbol is to prefix C# keywords in order to use them as variables. Although we cannot use keywords in order to use them as variables. Although we cannot use keywords such as bool and int as variables, the words @bool and @int are allowed.
Tuesday, March 16, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment