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))
.
You could put the values that you need to compare into an inline array and use a Contains extension method. See this article for starters.
Several snippets demonstrating the concept:
int index = 1;
Console.WriteLine("Example 1: ", new int[] { 1, 2, 4 }.Contains(index));
index = 2;
Console.WriteLine("Example 2: ", new int[] { 0, 5, 3, 4, 236 }.Contains(index));
Output:
Example 1: True
Example 2: False