Home > OS >  Is there a function to find range of numbers within a ObservableCollection?
Is there a function to find range of numbers within a ObservableCollection?

Time:03-09

Currently to find a specific value I do:

MyClass myclass = MyObservableList.FirstOrDefault(x => x.value == 5.54m);

However I want to be able to set a margin, instead of just looking for 5.54m, I want it to be a range of 5.53-5.55. Is there an easy way of doing that?

CodePudding user response:

Try this:

MyClass myclass =
    MyObservableList
        .Where(x => x.value >= 5.53m)
        .Where(x => x.value < 5.55m)
        .FirstOrDefault();
  • Related