本文介绍了切换案例情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在开关盒中提供具有参数的方法:
How to provide method which have parameters in switch case:
switch(input){
case"y":contact(no,value);
break;
}
当我这样做时它会给我错误。 PLZ帮助
[用评论代码更新]
when i am doing so its give me error. plz help
[Update with code from comment]
Console.Write("You have cross the limit of shares.Do you want to continue?(Y/N)");
string input = Console.ReadLine();
switch (input)
{
case "y":Calculateshare(share:, totalBalance:);
break;
case "n":
break;
}
在计算器共享附近的
错误是参数中缺少参数。
我尝试了什么:
尝试在切换案例中提供参数化方法。
near Calculateshare the error is Argument missing in parameters.
What I have tried:
Trying to provide parameterized method in switch case.
推荐答案
static void Main(string[] args)
{
Console.Write("You have cross the limit of shares.Do you want to continue?(Y/N)");
string input = Console.ReadLine();
switch (input)
{
case "y": Calculateshare(share: 5, totalBalance: 10);
break;
case "n":
break;
}
}
static void Calculateshare(int share, int totalBalance)
{
}
或
or
int share = 5;
int totalBalance = 10;
Console.Write("You have cross the limit of shares.Do you want to continue?(Y/N)");
string input = Console.ReadLine();
switch (input)
{
case "y": Calculateshare(share, totalBalance);
break;
case "n":
break;
}
这篇关于切换案例情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!