所以我試圖編寫一個程序來從用戶輸入一個字符串值。我正在嘗試使用開關來確定「a」和「b」之間被按下的內容。我不斷收到以下錯誤:參數1:無法從'方法組'轉換爲'布爾'。使用switch語句來確定用戶輸入是什麼
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
const string a = " You pressed a";
const string b = " You pressed b";
string input = Console.ReadLine();
switch(input)
{
case a:
ShowData(a);
break;
case b:
ShowData(b);
break;
default:
Console.WriteLine(" You did not type a or b");
Console.WriteLine();
Console.ReadLine();
break;
}
}
static void ShowData(string a)
{
Console.WriteLine(ShowData);
}
}
}
我想你想在'ShowData'方法中使用'Console.WriteLine(a);'。 – juharr
我首先試過,還有更多的錯誤。 – Abdulhamid