public class ExWorker
{
public void process(string type)
{
switch (type)
{
case "virtualcheck":
Console.WriteLine("virtual check in process");
break;
case "mastercard":
Console.WriteLine("mastercard in process");
break;
default :
break;
}
}
}
class Program
{
static void Main(string[] args)
{
ExWorker worker = new ExWorker();
worker.process("virtualcheck");
worker.process("mastercard");
}
}
找出此程序中的缺点并加一改进。
- 提问者网友:饥饿走向夜
- 2021-05-08 20:35
- 五星知识达人网友:胯下狙击手
- 2021-05-08 21:26
#define virtualcheck 1
#define mastercard 2
static class ExWorker
{
public void process(int type)
{
switch (type)
{
case virtualcheck:
Console.WriteLine("virtual check in process");
break;
case mastercard:
Console.WriteLine("mastercard in process");
break;
default :
break;
}
}
}
class Program
{
static void Main(string[] args)
{
ExWorker.process(virtualcheck);
ExWorker.process(mastercard);
}
}
- 1楼网友:深街酒徒
- 2021-05-08 21:47
public class ExWorker { public void process(string type) { switch (type) { case "virtualcheck": Console.WriteLine("virtual check in process"); break; case "mastercard": Console.WriteLine("mastercard in process"); break; default : break; // 这里的 break 是不需要的 应该删掉的 做到 前面的都不匹配直接执行 default break 是没有执行的机会的 不知道这算不算错误 } } } class Program { static void Main(string[] args) { ExWorker worker = new ExWorker(); worker.process("virtualcheck"); worker.process("mastercard"); } }