为什么没有排序的IList的< T>?!?! (编辑) [英] Why is there no Sort for IList<T>?!?! (edited)

查看:79
本文介绍了为什么没有排序的IList的< T>?!?! (编辑)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的惊讶,当我发现有没有直接的方法进行排序或执行上一个IList℃的二进制搜索; T>。就像有静态方法来进行排序和执行上的一组二进制搜索,我认为这将是有拿一个IList&LT类似的静态方法非常有帮助的; T>。

I was pretty surprised when I discovered that there is no direct way to sort or perform a binary search on an IList< T >. Just like there are static methods to sort and perform a binary search on an Array, I think that it would be awfully helpful to have similar static methods that take an IList< T >.

目前:

class Array
{
    static Sort<T>(T[] array);
    static int BinarySearch<T>(T[] array, T item);
}

我希望他们会增加:<​​/ P>

I wish they would add:

class List
{
    static Sort<T>(IList<T> list);
    static int BinarySearch<T>(IList<T> list, T item);
}

我看了一眼在.NET Framework 4.0 Beta版SDK和有还是不似乎是解决这个问题的。

I glanced at the .NET Framework 4.0 Beta SDK and there still doesn't appear to be a solution to this problem.

我知道我可以解决此通过创建来检查,如果它是一个List℃的扩展方法; T>,然后使用名单,其中排序/搜索; T>实例;然而,如果它不是一个名单,其中的一个实例; T>,那么我要执行复制(这太臭了非常大的列表)。我知道我能做到这一切,但为什么呢?是否有某种原因,他们故意忽略这个功能?

I know that I could work around this by creating an extension method that checks if it is a List< T > and then sort/search using the List< T > instance; however, if it is not an instance of a List< T >, then I have to perform a copy (which stinks for very large lists). I know I could do all of this, but why? Is there some reason they have intentionally omitted this feature?

要设法让这个在.NET 4.0框架,我已经建立,通过微软的Connect程序的建议。如果你感到沮丧和我一样对这个问题,投票就可以了,也许就会得到补充。

To try to get this in the .NET 4.0 Framework, I have created a suggestion via Microsoft's Connect program. If you are frustrated like me about this issue, vote on it and maybe it will get added.

<一个href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=474201">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=474201

推荐答案

LINQ有一个排序依据的方法在所有的IEnumerable&LT的作品; T&GT ;,其中的IList&LT; T&取代。您可以使用排序依据完成同样的事情。

LINQ has a OrderBy method that works on all IEnumerable<T>, including IList<T>. You can accomplish the same thing using OrderBy.

// Order a list of addresses:
IList<string> list = ...
var orderedList = list.OrderBy(input => input);

这篇关于为什么没有排序的IList的&LT; T&GT;?!?! (编辑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆