How would I search a range of ranged values using C#

后端 未结 8 1552
攒了一身酷
攒了一身酷 2021-02-10 20:24

I have a list of values like this

1000, 20400
22200, 24444

The ranges don\'t overlap.

What I want to do is have a c# function that can

8条回答
  •  囚心锁ツ
    2021-02-10 20:58

    I'd try the simplest option first, and optimize if that doesn't meet your needs.

    class Range {
       int Lower { get; set; }
       int Upper { get; set; }
    }
    
    List.FirstOrDefault(r => i >= r.Lower && i <= r.Upper);
    

提交回复
热议问题