如何输入要替换的字符串
(Environment.SpecialFolder.ApplicationData),因为 .ApplicationData 部分需要根据传递给它的变量进行更改。
string specialFolder = ("Environment.SpecialFolder." + specialLocation);
specialLocation = "this will change depending on path location";
path = Path.Combine(Environment.GetFolderPath("specialFolder"),
@""+backupPath);
希望我已经说得足够清楚了。
谢谢
最佳答案
使用Enum.TryParse就是你的答案
例如:
string s = "ApplicationData";
Environment.SpecialFolder sf;
if(Enum.TryParse<Environment.SpecialFolder>(s, true, out sf))
Console.WriteLine(Environment.GetFolderPath(sf));
因此,您的代码可以写为:
Environment.SpecialFolder sf;
if(Enum.TryParse<Environment.SpecialFolder>(specialLocation, true, out sf))
{
path = Path.Combine(Environment.GetFolderPath(sf), backupPath);
.....
}
关于c# - 环境.SpecialFolder问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19876754/