C # @ Character usage

Source: Internet
Author: User

1. Use the @ symbol to precede the string to indicate that the escape character is "not" handled.

If we write a path to a file, such as the Text.txt file under the "d:/text file" path, do not add the @ symbol as follows:

string " d://text File//text.txt ";

If you use the @ symbol, it's easier:

string @" d:/text File/text.txt ";

2. Let the string cross the line

Sometimes a string is written in a single line for a long time (such as an SQL statement), not with the @ symbol, one way:

string " SELECT * from HumanResources.Employee as e "    " INNER JOIN Person.Contact as C "    " On E.contactid = C.contactid "    " ORDER by C.lastname ";

With the @ symbol, you can change the line directly:

string @" SELECT * from HumanResources.Employee as e     INNER JOIN Person.Contact as C on     E.contactid = C.contactid     ORDER by C.lastname";

3. Usage in identifiers

C # does not allow keywords to be used as identifiers (class name, variable name, method name, tablespace name, and so on), but it is possible to add @ after it, for example:

namespace@namespace {class@class { Public Static void@static (int@int) {            if(@int >0) {System.Console.WriteLine ("Positive Integer"); }            Else if(@int = =0) {System.Console.WriteLine ("Zero"); }            Else{System.Console.WriteLine ("Negative Integer"); }         }     }}

Transferred from: http://blog.csdn.net/chanyinhelv/article/details/6044310

C # @ Character usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.