C# 排序xamarin形成可观测集合
在xamarin表单中,我有一个可观察的wordpress帖子集合 我想在此集合中按特定值对此集合进行排序 我怎样才能在Xamarin表单/c#中这样做 我可以看到有人在使用:C# 排序xamarin形成可观测集合,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,在xamarin表单中,我有一个可观察的wordpress帖子集合 我想在此集合中按特定值对此集合进行排序 我怎样才能在Xamarin表单/c#中这样做 我可以看到有人在使用: list.OrderByDescending(x => DateTime.Parse(x)).ToList(); 但这并不使用可观察集合或此集合中的特定值进行排序 我的对象填充如下: FlowObservableCollection<RootObject2> result = JsonConvert.
list.OrderByDescending(x => DateTime.Parse(x)).ToList();
但这并不使用可观察集合或此集合中的特定值进行排序
我的对象填充如下:
FlowObservableCollection<RootObject2> result = JsonConvert.DeserializeObject<FlowObservableCollection<RootObject2>>(await posts.Content.ReadAsStringAsync());
FlowObservableCollection结果=JsonConvert.DeserializeObject(wait posts.Content.ReadAsStringAsync());
是否有人能为我的数组排序提供解决方案
我要排序的值是一个子值,如:mycollection.group.Myvalue
提前谢谢 您可以尝试以下方法:
Collection = new ObservableCollection(Collection.OrderBy(x=>x.Date).ToList());
或者采用这种方法:
public static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)
{
var sortableList = new List<T>(collection);
sortableList.Sort(comparison);
for (int i = 0; i < sortableList.Count; i++)
{
collection.Move(collection.IndexOf(sortableList[i]), i);
}
}
publicstaticvoidsort(此ObservableCollection集合,比较)
{
var sortableList=新列表(集合);
可排序列表。排序(比较);
for(int i=0;i
您可以尝试以下方法:
Collection = new ObservableCollection(Collection.OrderBy(x=>x.Date).ToList());
或者采用这种方法:
public static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)
{
var sortableList = new List<T>(collection);
sortableList.Sort(comparison);
for (int i = 0; i < sortableList.Count; i++)
{
collection.Move(collection.IndexOf(sortableList[i]), i);
}
}
publicstaticvoidsort(此ObservableCollection集合,比较)
{
var sortableList=新列表(集合);
可排序列表。排序(比较);
for(int i=0;i
我不熟悉FlowObservableCollection
,但从我所能找到的来看,它似乎是ObservableCollection
的一个子类型
由于observedcollection
本身是Collection
的一个子类型,因此实现了IEnumerable
,因此使用its应该不会有任何问题,例如OrderBy
我可以看到有人在使用:
list.OrderByDescending(x => DateTime.Parse(x)).ToList();
list.OrderByDescending(x=>DateTime.Parse(x)).ToList()代码>
我要排序的值是一个子值,如:mycollection.group.Myvalue
您是否熟悉OrderByDescending()
示例中使用的as
如果不是,则在list.OrderByDescending(x=>DateTime.Parse(x)).ToList()中
术语x
指的是列表中的一个元素,您在=>
箭头右侧指定的内容是您的订购键
因此,如果您想按不同的值排序,只需编写类似于myCollection.OrderByDescending(x=>x.MyProperty)的代码即可
注意,您可以使用与x
不同的术语,只要它们在箭头两侧相同,例如myCollection.OrderByDescending(myElement=>myElement.MyProperty)代码>
最后请注意,调用myCollection.OrderByDescending()
会返回一个新的IEnumerable
,其中包含myCollection
中的元素,并且不会更改myCollection
本身
您不能将IEnumerable
强制转换为FlowObservableCollection
。因此,如果您需要一个有序的FlowObservableCollection
,您必须使用有序的IEnumerable
作为输入实例化一个新的集合
在您的情况下,它可能是这样的:
var orderedElements = myCollection.OrderByDescending(x => x.MyProperty);
var orderedCollection = new FlowObservableCollection<RootObject2>(orderedElements);`
var orderedElements=myCollection.OrderByDescending(x=>x.MyProperty);
var orderedCollection=新的FlowObservableCollection(orderedElements)`
我不熟悉FlowObservableCollection
,但从我所能找到的来看,它似乎是ObservableCollection
的一个子类型
由于observedcollection
本身是Collection
的一个子类型,因此实现了IEnumerable
,因此使用its应该不会有任何问题,例如OrderBy
我可以看到有人在使用:
list.OrderByDescending(x => DateTime.Parse(x)).ToList();
list.OrderByDescending(x=>DateTime.Parse(x)).ToList()代码>
我要排序的值是一个子值,如:mycollection.group.Myvalue
您是否熟悉OrderByDescending()
示例中使用的as
如果不是,则在list.OrderByDescending(x=>DateTime.Parse(x)).ToList()中
术语x
指的是列表中的一个元素,您在=>
箭头右侧指定的内容是您的订购键
因此,如果您想按不同的值排序,只需编写类似于myCollection.OrderByDescending(x=>x.MyProperty)的代码即可
注意,您可以使用与x
不同的术语,只要它们在箭头两侧相同,例如myCollection.OrderByDescending(myElement=>myElement.MyProperty)代码>
最后请注意,调用myCollection.OrderByDescending()
会返回一个新的IEnumerable
,其中包含myCollection
中的元素,并且不会更改myCollection
本身
您不能将IEnumerable
强制转换为FlowObservableCollection
。因此,如果您需要一个有序的FlowObservableCollection
,您必须使用有序的IEnumerable
作为输入实例化一个新的集合
在您的情况下,它可能是这样的:
var orderedElements = myCollection.OrderByDescending(x => x.MyProperty);
var orderedCollection = new FlowObservableCollection<RootObject2>(orderedElements);`
var orderedElements=myCollection.OrderByDescending(x=>x.MyProperty);
var orderedCollection=新的FlowObservableCollection(orderedElements)`
如果你能告诉我你想根据什么标准对这个集合进行排序会有帮助如果你能告诉我你想根据什么标准对这个集合进行排序会有帮助你好,谢谢你的回答,我正在尝试做这个FlowObservableCollection test=(FlowObservableCollection)result.OrderByDescending(x=>x.acf.product\u-date\u-group.product\u-date);
但它说“指定的强制转换不可用”您好,谢谢您的回答,我正在尝试这样做FlowObservableCollection测试=(FlowObservableCollection)结果。OrderByDescending(x=>x.acf.product\u-date\u-group.product\u-date);
但它说“指定的强制转换不可用”