Path String Concatenation Question in C#.

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-06-01T02:58:00Z Indexed on 2010/06/01 3:03 UTC
Read the original article Hit count: 358

Filed under:
|
|

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++] + "\\";
            }

    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about path