使用字面意义上'@'与一个字符串变量 [英] Using the literal '@' with a string variable

查看:125
本文介绍了使用字面意义上'@'与一个字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个辅助类从XML文件中提取的字符串。该字符串是文件路径(所以它有反斜杠它)。我需要使用该字符串,因为它是...我如何使用它就像我会用文字命令

I have a helper class pulling a string from an XML file. That string is a file path (so it has backslashes in it). I need to use that string as it is... How can I use it like I would with the literal command?

而不是这样:

string filePath = @"C:\somepath\file.txt";



我想这样做:

I want to do this:

string filePath = @helper.getFilePath(); //getFilePath returns a string

这是不是我如何真正使用它;它只是为了让我的意思更清晰一点。是否有某种.ToLiteral()什么的?

This isn't how I am actually using it; it is just to make what I mean a little clearer. Is there some sort of .ToLiteral() or something?

推荐答案

我不认为你有,如果你担心它已经具有值。 @操作是,当你指定(如在你的第一个代码片段)的字符串。

I don't think you have to worry about it if you already have the value. The @ operator is for when you're specifying the string (like in your first code snippet).

什么是你试图与路径字符串不是做工作?

What are you attempting to do with the path string that isn't working?

这篇关于使用字面意义上'@'与一个字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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