Combining multiple conditional expressions in C#

前端 未结 9 1210
一个人的身影
一个人的身影 2021-01-30 11:24

In C#, instead of doing if(index == 7 || index == 8), is there a way to combine them? I\'m thinking of something like if(index == (7, 8)).

9条回答
  •  轮回少年
    2021-01-30 12:04

    Do u need something like that

            int x = 5; 
    
            if((new int[]{5,6}).Contains(x)) 
            {
                Console.WriteLine("true");
    
    
            }
            Console.ReadLine();
    

提交回复
热议问题