ObservableCollection<Person> Persons = new ObservableCollection<Person>();
Persons.Add(new Person() { Name = "John 1", Age = 25, City = "New Delhi", Email ="abc@abc.com" });
Persons.Add(new Person() { Name = "John 2", Age = 25, City = "New Delhi", Email = "abc@abc.com" });
Persons.Add(new Person() { Name = "John 3", Age = 25, City = "New Delhi", Email = "abc@abc.com" });
Persons.Add(new Person() { Name = "John 4", Age = 25, City = "New Delhi", Email = "abc@abc.com" });
Persons.Add(new Person() { Name = "John 5", Age = 25, City = "New Delhi", Email = "abc@abc.com" });
Persons.Add(new Person() { Name = "John 6", Age = 25, City = "New Delhi", Email = "abc@abc.com" });
ObservableCollection<Person> PersonsNew = new ObservableCollection<Person>();
我的问题是,
PersonsNew
=跳过3并从Persons
获取4并将其存储在PersonsNew
ObservableCollection<Person>
但不是为Var
注意:仔细阅读输出应该在 ObservableCollection<Person>
修改
请参阅Persons
ObservableCollection,我在Person类中添加了6个成员,现在我需要从中过滤掉人员并将其存储在Person类的新ObservableCollection中,并说PersonNew
感谢........
答案 0 :(得分:4)
ObservableCollection<Person> PersonsNew = new ObservableCollection<Person>(Persons.Skip(3).Take(4));
或者,更简洁:
var PersonsNew = new ObservableCollection<Person>(Persons.Skip(3).Take(4));
如果您有一些可以从Persons集合中选择人员的标准,您还可以使用collection view。