C#中的字符串前面的@是什么?
它将字符串标记为逐字字符串文字。
在C#中,使用特殊符号@创建逐字字符串。@被称为逐字标识符。如果字符串包含@作为前缀,后跟双引号,则编译器将该字符串标识为逐字字符串,然后编译该字符串。@符号的主要优点是告诉字符串构造函数忽略转义符和换行符。
示例
using System;
using System.IO;
namespace DemoApplication{
class Program{
static void Main(string[] args){
Console.WriteLine("test string\n test string");
Console.WriteLine(@"test string \n test string");
//以下两个语句是相同的。
string jsonString1 = File.ReadAllText(@"D:\Json.json");
string jsonString2 = File.ReadAllText("D:\\Json.json");
Console.ReadLine();
}
}
}输出结果
上面代码的输出如下。
test string test string test string \n test string
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短