Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?

后端 未结 8 1980
闹比i
闹比i 2020-12-08 08:57

I happened to have seen some code where this guy passed a lambda expression to a ArrayList.Sort(IComparer here) or a IEnumerable.SequenceEqual(IEnumerable list, IEqualityCom

8条回答
  •  我在风中等你
    2020-12-08 09:45

    I'm not much sure what useful it really is, as I think for most cases in the Base Library expecting an IComparer there's an overload that expects a Comparison... but just for the record:

    in .Net 4.5 they've added a method to obtain an IComparer from a Comparison: Comparer.Create

    so you can pass your lambda to it and obtain an IComparer.

提交回复
热议问题