c#編程之@的3種作用
文章錄入:王子 責(zé)任編輯:7747.Net 5
【字體:
小大】
1.忽略轉(zhuǎn)義字符
例如
string fileName = "D:\\文本文件\\text.txt";
使用@后
string fileName = @"D:\文本文件\text.txt";
2.讓字符串跨行
例如
string strSQL = "SELECT * FROM HumanResources.Employee AS e"
" INNER JOIN Person.Contact AS c"
" ON e.ContactID = c.ContactID"
" ORDER BY c.LastName";
使用@后
string strSQL = @"SELECT * FROM HumanResources.Employee AS e
INNER JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
ORDER BY c.LastName";
3.在標(biāo)識符中的用法
C#是不允許關(guān)鍵字作為標(biāo)識符(類名、變量名、方法名、表空間名等)使用的,但如果加上@之后就可以了
例如
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");
}
}
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。