什么是@的字符串在C#中的前面? [英] What's the @ in front of a string in C#?

查看:149
本文介绍了什么是@的字符串在C#中的前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对C#(或可能VB.net)一个.NET的问题,但我试图找出什么是下面的声明之间的区别:

 字符串Hello =你好;
 

VS。

 字符串hello_alias = @你好;
 

打印出来在控制台上没什么区别,长度属性是相同的。

解决方案

它标志着字符串作为逐字字符串 - 任何通常会PTED为转义序列除$ P $字符串中被忽略<。 / P>

所以C:\\用户\\富是一样的 @C:\用户\富

This is a .NET question for C# (or possibly VB.net), but I am trying to figure out what's the difference between the following declarations:

string hello = "hello";

vs.

string hello_alias = @"hello";

Printing out on the console makes no difference, the length properties are the same.

解决方案

It marks the string as a verbatim string literal - anything in the string that would normally be interpreted as an escape sequence is ignored.

So "C:\\Users\\Rich" is the same as @"C:\Users\Rich"

这篇关于什么是@的字符串在C#中的前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆