У меня есть оператор switch, где первый случай равен «", поскольку я хочу проверить, является ли строка пустой. Моя проблема в том, что мне нужен другой случай, который может проверить, есть ли что-то внутри переменной «sName», но я не знаю, как это записать.У меня есть оператор switch, но я не знаю, как изменить его на то, как он мне нужен
Вы можете игнорировать то, что находится внутри случаев, но выделение жирным шрифтом, содержащее тире, является тем, которое мне нужно изменить.
(соответствующий код)
string sName = "";
int iChoice = 0;
switch (sName)
{
case "":
Console.Clear();
Console.WriteLine("You are not yet logged in, would you like to create a new account?\n");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("PLEASE NOTE: IF YOU ATTEMPT TO CREATE A NEW ACCOUNT WITH AN EXISTING NAME, YOUR PREVIOUS DATA WILL BE OVERWRITTEN!");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("\n1. Create a new account");
Console.WriteLine("2. Login");
iChoice = Convert.ToInt32(Console.ReadLine());
switch (iChoice)
{
case 1:
//outputs text to the console
Console.Write("What is your name? ");
//stores user input into variable sName
sName = Console.ReadLine();
//outputs text to the console
Console.Write("\nWhich school do you work at? ");
//stores user input into variable sSchool
sSchool = Console.ReadLine();
//outputs text to the console
Console.Write("\nWhat class do you teach? ");
//stores user input into variable sClass
sClass = Console.ReadLine();
//outputs the user's name
Console.WriteLine("\nYou are now logged in as " + sName + "\n");
//creates a new text file using the users name
using (StreamWriter sw = new StreamWriter(sName + ".txt"))
{
//writes to the text file using the variables
sw.WriteLine(sName);
sw.WriteLine(sSchool);
sw.WriteLine(sClass);
}
Console.Clear();
displayMenu();
iOption = Convert.ToInt32(Console.ReadLine());
break;
case 2:
//outputs text to the console
Console.Write("What is your name? ");
//stores user input into variable sName
sName = Console.ReadLine();
Console.Clear();
displayMenu();
iOption = Convert.ToInt32(Console.ReadLine());
break;
}
Console.ReadKey();
Console.Clear();
displayMenu();
iOption = Convert.ToInt32(Console.ReadLine());
break;
***case --------------------------------:***
{
Console.Clear();
Console.WriteLine("You are already logged in as " + sName);
Console.WriteLine("You are not yet logged in, would you like to create a new account?\n");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("PLEASE NOTE: IF YOU ATTEMPT TO CREATE A NEW ACCOUNT WITH AN EXISTING NAME, YOUR PREVIOUS DATA WILL BE OVERWRITTEN!");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("\n1. Create a new account");
Console.WriteLine("2. Login");
iChoice = Convert.ToInt32(Console.ReadLine());