【发布时间】:2016-02-01 16:21:42
【问题描述】:
问题:我的 else 语句无法访问,我做错了什么?
在编程方面非常新,我正在尝试比较类型,例如当我要求整数时人们无法输入字符串。
我的代码可能很糟糕,如果我能得到一个标题该怎么做以及为什么 if 参数跳过 else 部分,我会非常高兴!
谢谢!
class Program
{
static void Main(string[] args)
{
int integer = 0;
start:
Console.WriteLine("How old are you?: ");
int svar = int.Parse(Console.ReadLine());
Utility.CompareTypes(svar, integer);
if (true)
{
Console.WriteLine("Thanks");
}
else
{
Console.WriteLine("You have to enter a number!");
goto start;
}
}
}
class Utility
{
public static bool CompareTypes<T01, T02>(T01 type01, T02 type02)
{
return typeof(T01).Equals (typeof(T02));
}
}
:c
【问题讨论】:
-
那里有问题吗?
-
请避免在您的代码中使用
goto's,我认为这是非常糟糕的编码习惯 -
i(true) 错了,这样一行没有意义
标签: c# if-statement types compare unreachable-code