There is such a record:

int manInfo=8; ... switch(cMan[manInfo][0]) { case 1||8||17||24:...break; case 14||26||37||42:...break; ...//ΠΈ Ρ‚.Π΄. } 

This error occurs:

The operator "||" cannot be applied to int and int operands

Similarly with the case of string and string . Can operator || cannot be applied to case at all? Then how in my case would be the right thing to do?

  • 2
    "what do ha do?" - learn programming;) - Zowie
  • here and teach)) - blase

2 answers 2

Operator || in C #, it is applicable only to the bool type, so in your case it will be more convenient to use something like the extansion method:

 public static bool In<T>(this T source, params T[] list) { if(null==source) throw new ArgumentNullException("source"); return list.Contains(source); } ... if(cMan[manInfo][0].In(1, 8, 17, 24)) { ... } ... 
  • Wow! Perhaps this is the way I will apply, thanks! - blase
  • Why check null==source ? Why do you think foo.In(2,3,5,null) cannot be checked? - Pavel Mayorov 1:16 pm
 case 1: case 8: case 17: ... break; 
  • thank you! - blase