快速的IComparer? [英] Quick IComparer?
本文介绍了快速的IComparer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我去重新发明轮子,就是在那里创建一个的IComparer和其中的一些框架的方式; T>
从 Func键< T,T,INT和GT ;
Before I go reinventing the wheel, is there some framework way of creating an IComparer<T>
from a Func<T,T,int>
?
修改
IIRC(它已经有一段时间)的Java支持匿名接口实现。请问这种结构存在于C#,或者是代表认为一个完整的备选方案?
IIRC (it's been a while) Java supports anonymous interface implementations. Does such a construct exist in C#, or are delegates considered a complete alternative?
推荐答案
在即将到来的.NET4.5(的Visual Studio 2012)这个是可能的静态工厂方法比较器&LT;&GT; .Create
。例如
In the upcoming .NET4.5 (Visual Studio 2012) this is possible with the static factory method Comparer<>.Create
. For example
IComparer<Person> comp = Comparer<Person>.Create(
(p1, p2) => p1.Age.CompareTo(p2.Age)
);
这篇关于快速的IComparer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文