C# 中字串前的 @ 符號表示什麼?
它將字串標記為一個原文字串字面值。
在 C# 中,使用特殊符號 @ 建立原文字串。@ 被稱為原文識別符號。如果一個字串包含了字首 @ 後面緊跟雙引號,那麼編譯器就會將該字串識別為原文字串,並對該字串進行編譯。@ 符號的主要優點是告訴字串建構函式忽略跳脫字元和換行符。
示例
using System;
using System.IO;
namespace DemoApplication{
class Program{
static void Main(string[] args){
Console.WriteLine("test string
test string");
Console.WriteLine(@"test string
test string");
//Both the below statements are same.
string jsonString1 = File.ReadAllText(@"D:\Json.json");
string jsonString2 = File.ReadAllText("D:\Json.json");
Console.ReadLine();
}
}
}輸出
以上程式碼的輸出如下。
test string test string test string
test string
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP