快速的IComparer?快速、IComparer

由网友(执笔写我心)分享简介:在我去重新发明轮子,就是在那里创建一个的IComparer和其中的一些框架的方式; T> 从 Func键< T,T,INT和GT ; Before I go reinventing the wheel, is there some framework way of creating an ICompar...

在我去重新发明轮子,就是在那里创建一个的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)
    );
阅读全文

相关推荐

最新文章