【发布时间】:2009-12-14 18:48:54
【问题描述】:
我想要做的是,当使用我的程序的人在没有任何内容的情况下点击输入时,它不会导致错误这是程序的一部分:
Console.WriteLine("4.-Ya no quiero jugar >.<");
int opc = Convert.ToInt16(Console.ReadLine());
switch (opc)
{
case 1:
Console.WriteLine("omg");
break;
case 2:
Console.WriteLine("wtf");
break;
default:
Console.WriteLine("Cant do that >.>");
Console.ReadKey();
break;
etc.
}
问题是我使用整数,我尝试这样做
string opc1=console.readline();
if (opc =="")
{
console.writeline("nope,try again");
}
else
{ // Brace was omitted in original - Jon
int opc = Convert.ToInt16(Console.ReadLine());
switch (opc)
blah blah.
以及它的不同组合 >.
希望有人能帮我解决一下>.
【问题讨论】:
-
在Java中比较我用equals方法,对c#一窍不通,你试过
if opc.equals("")吗? -
没有尝试过,但如果 tryparse 不起作用,我会尝试 tyvm