I wrote this check in C# to perform some value checking:
if ((x <= 20 && y <= 5) || (x <= 30 && y <= 10) ||
(x <= 50 && y <= 15) || (x <= 70 && y <= 20) ||
(x <= 70 && y <= 30))
{
// do something
}
I’m in the process to learn LINQ, and I would like to change the above code to use LINQ,
If you submit a code, can you please add some comment to explain the conversion.
If you really wanted to use LINQ, one way would be to store a collection of tuples that represented each of the cases (upper-bounds) and then use the
Enumerable.Anymethod to test if an(x, y)pair met any of the possible conditions.Example (in reality, you can create the collection once and give it longer lifetime, perhaps through a field-reference):