像(伪代码)的东西
ObservableCollectionob1 = new ObservableCollection (); ob1.Add(...); ob1.Add(...); ob1.Add(...); ob1.Add(...); ObservableCollection ob2; ob2 = ob1.Range(0, 2);
考虑到两个集合都可以包含大量数据.
谢谢
ObservableCollectionob1 = new ObservableCollection (); ob1.Add(...); ob1.Add(...); ob1.Add(...); ob1.Add(...); ObservableCollection ob2; // ob2 = ob1.Range(0, 2); ob2 = new ObservableCollection(ob1.Skip(0).Take(2));
现在如果你真的坚持这种.Range
方法,你可以自己写一个扩展:
public static class ObservableCollectionExtensions { public static ObservableCollectionRange(this ObservableCollection sequence, int start, int count) { return new ObservableCollection(sequence.Skip(start).Take(count)); } }
现在你的代码应该编译:
ObservableCollectionob1 = new ObservableCollection (); ob1.Add(...); ob1.Add(...); ob1.Add(...); ob1.Add(...); ObservableCollection ob2; ob2 = ob1.Range(0, 2);