什么是逐字字符串? [英] What is a verbatim string?

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

问题描述

从ReSharper,我知道

From ReSharper, I know that

var v = @"something";

制作v称为 verbatim字符串。这是什么,使用它的常见情况是什么?

makes v something called a verbatim string. What is this and what is a common scenario to use it?

推荐答案

这意味着不需要转义特殊字符,因为您已告知编译器期望特殊字符并忽略它们。常见的用例是指定连接字符串:

It means that special chars don't need to be escaped, since you informed the compiler to expect special characters, and to ignore them. A common use case might be to specify a connection string:

string sqlServer = @"SERVER01\SQL"; 

这是完全有效的,与通常使用反斜杠被认为是转义字符的情况相反。

This is perfectly valid, as opposed to in normal use where the backslash would be considered an escape character.

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

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