订购的ObservableCollection< T>而无需创建一个新的 [英] Order a ObservableCollection<T> without creating a new one
问题描述
我有下面的代码重新整理一个的ObservableCollection< T>
系列:
列表=新的ObservableCollection<&SOMETYPE GT;(list.OrderBy(C => c.Ordinal));
这个代码的工作,但我不喜欢那个新涉及的事实。有没有一种方法,我可以改变的内部元素顺序的ObservableCollection< T>
集合,而无需创建一个新的
<? p>谢谢,
由于排序依据
也是新闻了一个数组以配合您的收藏,和其他几个对象的大小,你已经两个选择:
- 放弃对LINQ的OrderBy干脆写自己的排序执行就地使用Move方法在您的ObservableCollection排序。
- 等到当前的实现变得有问题再申请1。
别担心,newing东西了没那么可怕。 LINQ做这一切的时候。除非这是一个瓶颈,一切都很好。除非有令人信服的证据表明在地方真的会加快展会排序,那么这里是没有问题的。
I have following code to re-order a ObservableCollection<T>
collection:
list = new ObservableCollection<SomeType>( list.OrderBy( c=>c.Ordinal ) );
This code works, but I don't like the fact that "new" is involved. Is there a way I can change the internal element order of a ObservableCollection<T>
collection without creating a new one?
Thanks,
Given that OrderBy
also news up an array to match the size of your collection, and several other objects, you've two choices:
- Give up on LINQ OrderBy altogether and write your own sort that performs in-place sorting over your ObservableCollection using the Move method.
- Wait until the current implementation becomes problematic then apply 1.
Don't worry, newing stuff up isn't so terrible. Linq does it all the time. Unless it's a bottleneck, all is good. Unless there's compelling evidence that sorting in-place will really speed up the show, then there's no problem here.
这篇关于订购的ObservableCollection< T>而无需创建一个新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!