C#中字符串前面的@是什么?

编程入门 行业动态 更新时间:2024-10-22 16:49:18
本文介绍了C#中字符串前面的@是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

string hello = "hello";

对比

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.

所以 "C:\Users\Rich" 和 @"C:UsersRich"

有一个例外:双引号需要转义序列.要转义双引号,您需要连续放置两个双引号.例如,@"""" 的计算结果为 ".

There is one exception: an escape sequence is needed for the double quote. To escape a double quote, you need to put two double quotes in a row. For instance, @"""" evaluates to ".

更多推荐

C#中字符串前面的@是什么?

本文发布于:2023-11-08 14:03:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!