• c# 中@ 的三种用法


    以前只知道@在C#中为了写文件路径的不要加转义符而在前面加上@标识符,没想到@还有其他的作用

    1.忽略转义字符
    例如

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

    使用@后

    1
    string fileName = @"D:文本文件 ext.txt";

    2.让字符串跨行
    例如

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

    使用@后

    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.在标识符中的用法

    C#是不允许关键字作为标识符(类名、变量名、方法名、表空间名等)使用的,但如果加上@之后就可以了
    例如

    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");
                }
    }
  • 相关阅读:
    hdu 1896 stones
    各种类型的取值范围
    RSS/PSS/VSZ
    kasan BUG log
    ARM机器码分析
    Linux进程状态
    谢宝友: 深入理解RCU之七:分级RCU实现
    rcu_preempt detected stalls on CPUs/tasks
    Linux 内核 hlist
    linux cmd
  • 原文地址:https://www.cnblogs.com/maweiwei/p/10394733.html
Copyright © 2020-2023  润新知