Path String Concatenation Question in C#.
- by Nano HE
Hello.
I want to output D:\Learning\CS\Resource\Tutorial\C#LangTutorial
But can't work. Compiler error error CS0165: Use of unassigned local variable 'StrPathHead
Please give me some advice about how to correct my code or other better solution for my case. Thank you.
static void Main(string[] args)
{
string path = "D:\\Learning\\CS\\Resource\\Book\\C#InDeepth";
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++] + "\\";
}
}
}