私は文字列が空であるかどうかをチェックしたい最初のcaseが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());