切换案例情况 [英] Switch case condition

查看:83
本文介绍了切换案例情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在开关盒中提供具有参数的方法:

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.

推荐答案

请参阅切换(C#参考) [ ^ ]和方法参数(C#参考) [ ^ ]。
See switch (C# Reference)[^] and Method Parameters (C# Reference)[^].


尝试:



casey:

联系人(不,价值);

休息;



最有可能是一个或两个参数'no和'值未定义。



如果方法contact在其他一些中定义class,那么只有你有一个有效的引用才能使用它...这可以通过几种不同的方式发生。



如果'联系是在静态类中定义为静态方法,然后将静态类名放在方法调用中:someStaticClassName.contact(no,value);



编译错误应该在这里给你关于这个问题的信息。
try:

case "y":
contact(no,value);
break;

most likely one, or both of your parameters 'no and 'value are undefined.

if the method "contact" is defined in some other class, then you will be able to use it only if you have a valid reference to it ... which can happen in several different ways.

if 'contact is defined as a static method in a static class, then put the static class name in the method call: someStaticClassName.contact(no, value);

the compile error should give you information about the problem here.


验证你的语法



verify your syntax

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;
            }


这篇关于切换案例情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆