C# Switch语句

来源:百度知道 编辑:UC知道 时间:2024/05/12 18:13:07
很郁闷啊
告诉我下面这段代码错在哪了 为什么运行不了……
只要能运行就好 谢谢
string A = "1";
string B ="2";

string C;
Console.WriteLine("1和2");
C=Console.ReadLine();
switch ( C.ToLower())
{
case A:
Console.WriteLine("4");
break;
case B:
Console.WriteLine("3");
break;
default:
Console.WriteLine("输入错误");
break;
}
Console.WriteLine("123");
Console.ReadKey();

case A 改成 case "A", 其他的一样。

C.ToLower()是转化为小写
所以应该
case "a": ....
case "b": ....

case A: 等 中的A 只能够使常量,(不能够用变量)
所以 错了!

C.ToUpper()转换成大写的