0

I'm trying to have a user enter a file path as a string (but for learning purposes I'd like to treat the path as any string variable, but I am open to suggestions for file path validation). The issue I am having and cannot seem to figure out is once inFilepath is updated from Console.ReadLine(), it only will show up in the Console.WriteLine() statement that concatenates it. Trying to display it anywhere else displays "", which I know indicates that the variable was not updated since its assignment as "". I believe this is a scope issue, but I am at a loss as to why, in the end I just need to access the updated inFilepath in the same scope as its declaration.

string correctPath = "no";
string inFilepath = "";
bool flag = false;
bool inFlag = false;
while (!flag) {
    Console.WriteLine("Please Enter the Tour file path now...");
    inFilepath = Console.ReadLine();
    inFilepath += "\\";
    while (!inFlag) {
        Console.WriteLine("Is this the correct filepath: " + inFilepath + "  ?" +
        "\n Enter 'no' if it is incorrect or 'yes' if it is correct.");
        correctPath = Console.ReadLine();
        if (correctPath == "yes") {
            inFlag = true;
            flag = true;
        }
        else {
            break;
        }
    }
}
Console.WriteLine("path: ", inFilepath);

1 Answer 1

1

Your problem is here, you are passing the param arg, but not using/displaying it

Console.WriteLine("path: ", inFilepath);

You need to add {0}, like

Console.WriteLine("path: {0}", inFilepath);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.