jeudi 23 janvier 2020

How to Pass String Variable Value Outside If-Statements in C#?

I am new to programming and I want to pass the value of string variable "serverPath" to string variable "DestinationPath". however, I am having this error "use of unassigned variable". this is my code:

        string DestinationPath;
        string serverPath;

        if (ServerList.SelectedItem.Value == "1")
        {
            serverPath = "10..13.58.17";
        }
        else if (ServerList.SelectedItem.Value == "2")
        {
            serverPath = "10..13.58.33";
        }

        DestinationPath = @"\\"+serverPath+"\C$\TEST FOLDER\DESTINATION FOLDER";

what am I doing wrong here? how can I pass the value of serverPath outside the If-statement? Any help will be appreciated. Thank you.

Aucun commentaire:

Enregistrer un commentaire