本文介绍了使用枚举+切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么我的Switch语句在这样的情况下不起作用:
I want to know why my Switch statement is not working if I have something like this:
public enum cond
{ checknum,
checkval
}
private string data()
{ cond condtype = cond.checknum;
switch (condtype)
{ case cond.checknum:
// ... code
break;
}
}
似乎永远都不要输入任何条件类型...
有什么主意吗?
It looks like never enter in any condtype...
any idea ?
推荐答案
private string data()
{ cond condtype = cond.checknum;
switch (condtype)
{ case cond.checknum:
// ... code
break;
}
}
但是,这根本没有任何意义.为什么需要开关来确定已设置的内容?
However, this makes no sense at all. Why do you need a switch to determine what you have already set?
class Program
{
public enum cond
{
checknum,
checkval
}
static private void data()
{
cond condtype = cond.checknum;
switch (condtype)
{
case cond.checknum:
Console.WriteLine("I am checknum");
break;
case cond.checkval:
Console.WriteLine("I am checkval");
break;
default:
Console.WriteLine("I am no one");
break;
}
}
static void Main(string[] args)
{
data();
Console.ReadKey();
}
}
我建议您在代码的其他方面查看该问题.
HTH
I suggest you look at other areas of the code for the problem.
HTH
这篇关于使用枚举+切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!