Evaluate Expressions in Switch Statements in C#

前端 未结 12 482
抹茶落季
抹茶落季 2021-01-31 01:42

I have to implement the following in a switch statement:

switch(num)
{
  case 4:
    // some code ;
    break;
  case 3:
    // some code ;
    brea         


        
12条回答
  •  悲哀的现实
    2021-01-31 02:09

    you can do this

    switch (mark)
    {
        case int n when n >= 80:
            Console.WriteLine("Grade is A");
            break;
    
        case int n when n >= 60:
            Console.WriteLine("Grade is B");
            break;
    
        case int n when n >= 40:
            Console.WriteLine("Grade is C");
            break;
    
        default:
            Console.WriteLine("Grade is D");
            break;
    }
    

提交回复
热议问题