在C#中提供文件的路径 [英] Giving path of a file in C#

查看:91
本文介绍了在C#中提供文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打开保存在计算机桌面上的 xxx.txt文件 ,但是程序给出了

I want to open a xxx.txt file kept on desktop of my Computer but the program gives an

错误解析器错误,无法识别转义序列'\ D'.我正在尝试给出

文件为"C:\ Documents and Settings \ user \ Desktop \ xxx.txt" .

我是用正确的方式给出路径还是有其他方法给出路径

推荐答案

\是C#字符串中的转义字符.它用于特殊字符,例如换行符(\n).要编写文字\,您必须用另一个\引用:

\ is an escape character in C# strings. It is used for special characters, such as line break (\n). To write a literal \ you have to quote with another \:

string myFileName = "C:\\Documents and Settings\\user\\Desktop\\xxx.txt";

另一种方法是禁用对@字符的字符串引用:

An alternative is to disable quoting for the string with the @ character:

string myFileName = @"C:\Documents and Settings\user\Desktop\xxx.txt";

这篇关于在C#中提供文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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