Multi-variable switch statement in C#

后端 未结 12 504
-上瘾入骨i
-上瘾入骨i 2020-12-15 16:54

I would like use a switch statement which takes several variables and looks like this:

switch (intVal1, strVal2, boolVal3)
{
   case 1, \"hello\", false:
            


        
12条回答
  •  生来不讨喜
    2020-12-15 17:51

    //.Net Core 3.1
        class Convertors
        {
            static void Main(string[] args)
            {
                Console.WriteLine(Convertors.ConvertAny("m","cm", 10));
                Console.ReadKey();
            }
            public static double MToCM(double value)
            {
                return value * 100;
            }
            public static double ConvertAny(string srcUOM, string tgtUOM, double value)
            {
                switch (srcUOM.ToLower(), tgtUOM.ToLower())
                {
                    case ("m", "cm"): return Convertors.MToCM(value);
                    default: throw new NotImplementedException();
                }
            }
        }
    

提交回复
热议问题