请问C#鲜明的()方法保留序列的原始顺序不变? [英] Does C# Distinct() method keep original ordering of sequence intact?

查看:113
本文介绍了请问C#鲜明的()方法保留序列的原始顺序不变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除列表,从重复的,在不改变列表中的独特元素的顺序

I want to remove duplicates from list, without changing order of unique elements in the list.

乔恩斯基特&安培;其他人建议使用以下

Jon Skeet & others have suggested to use following

list = list.Distinct().ToList();

从列表C#删除重复

在C#的列表中删除重复

能够保证所有的独特顺序元素会和以前一样?如果是,请即证实了文件就可以了这个,因为我无法找到任何一个参考。

Is it guaranteed that the order of unique elements would be same as before? If yes, please give a reference that confirms this as I couldn't find anything on it in documentation.

推荐答案

它不能保证的,但它是最明显的实现。这将是很难以流方式来实现(即,使得它,只要它可以返回的结果,具有读为小,因为它可以)的的,以便返回它们

It's not guaranteed, but it's the most obvious implementation. It would be hard to implement in a streaming manner (i.e. such that it returned results as soon as it could, having read as little as it could) without returning them in order.

您可能需要阅读上的 Edulinq实现鲜明()的。

You might want to read my blog post on the Edulinq implementation of Distinct().

请注意,即使这是保证LINQ到对象(其中我个人认为它的定)并不意味着对其他LINQ提供者,如LINQ to SQL的东西。

Note that even if this were guaranteed for LINQ to Objects (which personally I think it should be) that wouldn't mean anything for other LINQ providers such as LINQ to SQL.

担保的范围内提供LINQ到对象的水平有点不一致,有时,海事组织。一些优化被记录,则不能。哎呀,有些文档是平出的错误

The level of guarantees provided within LINQ to Objects is a little inconsistent sometimes, IMO. Some optimizations are documented, others not. Heck, some of the documentation is flat out wrong.

这篇关于请问C#鲜明的()方法保留序列的原始顺序不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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