开发者

filter Observable ObservableCollection - WPF

开发者 https://www.devze.com 2023-03-09 03:04 出处:网络
ObservableCollection<Person>Persons = new ObservableCollection<Person>(); Persons.Add(new Person() { Name = \"John 1\", Age = 25, City = \"New Delhi\", Email =\"abc@abc.com\" });
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>();

My question is,

PersonsNew = skip 3 and Take 4 from Persons and Store it in PersonsNew as ObservableCollection<Person> 开发者_如何学C but not as Var

NOTE: Read carefully out put should be in ObservableCollection<Person>

EDIT: See, Persons ObservableCollection, i have added 6 member in it of Person Class, now i need to have filterd persons from it and store it in new ObservableCollection of Person class say PersonNew Thanks........


ObservableCollection<Person> PersonsNew = new ObservableCollection<Person>(Persons.Skip(3).Take(4));

Or, more succinctly:

var PersonsNew = new ObservableCollection<Person>(Persons.Skip(3).Take(4));

If you have some criteria by which people can be selected from the Persons collection, you could also use a collection view.

0

精彩评论

暂无评论...
验证码 换一张
取 消