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