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
热门推荐
3 年月日祝福语简短
10 国庆求婚祝福语简短精辟
11 给侄子祝福语简短精辟
12 生日贺卡祝福语 简短独特
13 上嫂子生日祝福语简短
14 嫂子生日的祝福语简短
15 幼儿祝福语大全简短卡片
16 订婚新发言简短祝福语
17 三八简短祝福语给婆婆
18 3岁孩子祝福语简短