The role of a character in C # @

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/u011966339/article/details/90236700

Previously only know @ In C # to write a file path \ escape but do not add the identifier with @ in front, I did not think there are other role!

1. Ignore the escape character
, for example,

1

string fileName = "D:\\文本文件\\text.txt";

After use

1

string fileName = @"D:\文本文件\text.txt";

 

2. Let the string interbank
example

1

2

3

4

string strSQL = "SELECT * FROM HumanResources.Employee AS e"

   " INNER JOIN Person.Contact AS c"

   " ON e.ContactID = c.ContactID"

   " ORDER BY c.LastName";

 

After use

1

2

3

4

string strSQL = @"SELECT * FROM HumanResources.Employee AS e

    INNER JOIN Person.Contact AS c

    ON e.ContactID = c.ContactID

    ORDER BY c.LastName";

3. Usage identifier

C # is not allowed to use keywords as identifiers (like variable names, method names, table space, etc.), but then if coupled with @ on it
, for example,

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

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");

            }

}

  

Guess you like

Origin blog.csdn.net/u011966339/article/details/90236700