所以,我試圖做一個循環,如果有人輸入一個字符它會執行。如果它是錯的,它將不會顯示一個選項。如果我在Array()方法之後的末尾添加Else {Console.WriteLine("Not an option")
,它也不起作用。 所以,我不完全確定我在做什麼。這是否甚至需要一個循環?正如我想象的那樣工作?任何建議都會很棒。循環char不工作
class Program
{
static void Main(string[] args)
{
string _a = "";
constructor dick = new constructor();
Console.WriteLine("Enter C for constructor, M for method, A for an array...");
Console.WriteLine("Please reference source code to have full details and understanding...");
while (_a.ToUpper() == "C" || "M" || "A")
{
_a = Console.ReadLine();
if (_a.ToUpper() == "C")
{
Console.WriteLine(dick.a);
}
if (_a.ToUpper() == "M")
{
Shit();
}
if (_a.ToUpper() == "A")
{
Array();
}
}
}
public class constructor
{
public string a = "This is a constructor!";
}
static public void Shit()
{
string b = "This is a method!";
Console.WriteLine(b);
}
static public void Array()
{
Console.WriteLine("\nHow large of an array?\n");
string sSize = Console.ReadLine();
int arraySize = Convert.ToInt32(sSize);
int[] size = new int[arraySize];
Random rd = new Random();
Console.WriteLine();
for (int i = 0; i < arraySize; i++)
{
size[i] = rd.Next(arraySize);
Console.WriteLine(size[i].ToString());
}
}
}
}
我建議你的名字您的對象以更合適的方式。 – Szymon
你可能想用'switch'語句嘗試它,打破每種情況。事實上,即使第一個匹配,你也執行所有的'if'。 – HABO