Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WP7可观察收集排序_C#_Windows Phone 7_Sorting_Observablecollection - Fatal编程技术网

C# WP7可观察收集排序

C# WP7可观察收集排序,c#,windows-phone-7,sorting,observablecollection,C#,Windows Phone 7,Sorting,Observablecollection,我有一个收藏: public ObservableCollection<Shops> ShopList { get; set; } ShopList现在有4个空元素。为什么会这样?如何更正代码? 谢谢这是正确的顺序: var orderedlist = ShopList.OrderBy(k => k.Name); ShopList.Clear(); foreach (Shops s in orderedlist) ShopList.Add((Shops)s); Sh

我有一个收藏:

public ObservableCollection<Shops> ShopList { get; set; }
ShopList现在有4个空元素。为什么会这样?如何更正代码?
谢谢

这是正确的顺序:

var orderedlist = ShopList.OrderBy(k => k.Name);
ShopList.Clear();
foreach (Shops s in orderedlist)
    ShopList.Add((Shops)s);

ShopList.Clear()清除列表:)是的,我很笨,顺序错误:dd也许你对
SortedObservableCollection
感兴趣:这对我不好,orderedlist将有空元素如果你清除shoplist,我设法解决了它购买将元素复制到新集合,然后清除
var orderedlist = ShopList.OrderBy(k => k.Name);
ShopList.Clear();
foreach (Shops s in orderedlist)
    ShopList.Add((Shops)s);