我想输出D:\Learning\CS\Resource\Tutorial\C#LangTutorial 但不能工作。编译器错误错误 CS0165:使用未分配的局部变量 'StrPathHead 请给我一些关于如何更正我的代码或其他更好的解决方案的建议。谢谢你。
static void Main(string[] args)
{
string path = "D:\\Learning\\CS\\Resource\\Book\\C#InDepth";
int n = 0;
string[] words = path.Split('\\');
foreach (string word in words)
{
string StrPathHead;
string StrPath;
Console.WriteLine(word);
if (word == "Resource")
{
StrPath = StrPathHead + word + "\\Tutorial\\C#LangTutorial";
}
else
{
StrPathHead += words[n++] + "\\";
}
}
}