Say i have a class that contains these items publicly accessible via properties:
class MyClass
{
int switch1; //0 or 1
int switch2; //0 or 1
int switch3; //0 or 1
}
This class represents switch states, and each time a switch state changes, i would like to add it to my transition list
I have a large sorted list that contains instances of this class and would like to use a query to capture only the entries in my list where the switch state for any switch changes.
Is this possible using a linq query?
try this:
Assuming your class looks like:
I just added an
Equals()to compare flags and myIdfield is purely to demonstrate which items changed.We can then craft a LINQ query like:
Not elegant, but it works, if you had this data set:
And ran the query, the list would contain your state transitions at items: 0, 2, 3, 6, 7, 9