C# lambda expressions and IComparer

前端 未结 4 911
闹比i
闹比i 2021-02-04 03:15

I am using lambda expressions to sort and search an array in C#. I don\'t want to implement the IComparer interface in my class, because I need to sort and search on multiple m

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 03:37

    if you want to avoid using external libraries, another option for you would be to first filter out the array and object. e.g.

    int index = Array.BinarySearch(
      widgets.Select(x=>x.foo).ToArray(),
      x.foo)
    

提交回复
热议问题