如何使用" \"在没有使它的转义序列的字符串 - C#? [英] How to use "\" in a string without making it an escape sequence - C#?

查看:222
本文介绍了如何使用" \"在没有使它的转义序列的字符串 - C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这确实基本,我不知道,但我怎么让它不承认\作为一个字符串

I'm sure this is something really basic that I don't know but how do I make it not recognize "\" as an escape sequence inside a string

我想输入一个路径,它认为它是一个转义序列

I'm trying to type in a path and it thinks it is an escape sequence

推荐答案

您可以使用的逐字字符串

//Initialize with a regular string literal.
string oldPath = "c:\\Program Files\\Microsoft Visual Studio 8.0";

// Initialize with a verbatim string literal.
string newPath = @"c:\Program Files\Microsoft Visual Studio 9.0";
                 ↑

这篇关于如何使用" \"在没有使它的转义序列的字符串 - C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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