我有一个集合:
public ObservableCollection<Shops> ShopList { get; set; }
然后我把4个元素放入其中(它显示正确),我尝试对它们进行排序
ShopList.Clear();
var orderedlist = ShopList.OrderBy(k => k.Name);
foreach (Shops s in orderedlist)
ShopList.Add((Shops)s);
ShopList现在有4个null元素。为什么这样,以及如何纠正代码? 感谢
答案 0 :(得分:2)
这是正确的顺序:
var orderedlist = ShopList.OrderBy(k => k.Name);
ShopList.Clear();
foreach (Shops s in orderedlist)
ShopList.Add((Shops)s);