there is something wrong with my c# program, and i need assistance.

Weber Chang 20 Reputation points
2024-04-22T12:51:02.23+00:00

Here's how my program like, or you can also see it from attached image:screen capture 2024-04-22 204515partial class Boot

{

static void Main()

{

    Console.WriteLine("please input the path of your data store.");

    string ds_path = Console.ReadLine();

    try

    {

        while (true)

        {

            if (string.IsNullOrWhiteSpace(ds_path))

            {

                Console.WriteLine("you CAN'T setup your data store on an EMPTY path, please reinput!!!");

                ds_path = Console.ReadLine();

            }

            else

            {

                break;

            }

        }

         if (Directory.Exists(ds_path))

         {

             Console.WriteLine("you've HAD this path for other use, please reinput path!!!");

             ds_path = Console.ReadLine();

         }

         else

         {

             Directory.CreateDirectory(ds_path);

             Console.WriteLine("successfully created directory!");

         }

    }

    catch (Exception e)

    {

        Console.WriteLine("ERROR in creating directory: " + e.Message);

    }

}
```}

when i run this program, the windows powershell shows the line of words:

please input the path of your data store.

and when i input D:\data_store, which is already created and used for other purpose on my PC, 

the powershell shows:

you've HAD this path for other use, please reinput path!!!

but something weired happened: the program doesn't run as planned, but it stopped with the followed words:D:\codes of vs\ConsoleApp2\bin\Debug\net8.0\ConsoleApp2.exe (process 16672) exited with code 0.

 

this program is used to create the data store directory of my program, when the input thing is empty it will ask the user to reinput, and if not, it will detect whether this path is used, i mean the path is already exist, if so, it will ask the user to reinput, till the user input a not-empty and not-used path.
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,649 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 61,731 Reputation points
    2024-04-22T17:44:41.2366667+00:00

    you program loops until non-blank string entered, then exits loop.

    after loop if checks if directory exists, if so, prints message, ask for input, then exits, as there is no code to re-renter the loop. you probably wanted the while loop to include the directory test.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful