2011-05-28 100 views
0
ObservableCollection<Person> Persons = new ObservableCollection<Person>(); 

Persons.Add(new Person() { Name = "John 1", Age = 25, City = "New Delhi", Email ="[email protected]" }); 

Persons.Add(new Person() { Name = "John 2", Age = 25, City = "New Delhi", Email = "[email protected]" }); 

Persons.Add(new Person() { Name = "John 3", Age = 25, City = "New Delhi", Email = "[email protected]" }); 

Persons.Add(new Person() { Name = "John 4", Age = 25, City = "New Delhi", Email = "[email protected]" }); 

Persons.Add(new Person() { Name = "John 5", Age = 25, City = "New Delhi", Email = "[email protected]" }); 

Persons.Add(new Person() { Name = "John 6", Age = 25, City = "New Delhi", Email = "[email protected]" }); 

     ObservableCollection<Person> PersonsNew = new ObservableCollection<Person>(); 

我的問題是,
PersonsNew =跳過3和Persons取4和PersonsNew存儲作爲ObservableCollection<Person> 但不Var過濾器可觀察到的ObservableCollection - WPF

注:仔細閱讀輸出應該在ObservableCollection<Person>

編輯: 見,Persons的ObservableCollection,我已經在它的Person類增加6個成員,現在我需要從它filterd人並將其存儲在Person類的新的ObservableCollection說PersonNew 感謝。 .......

+3

我不知道你的問題是什麼? – 2011-05-28 10:46:56

+0

請參閱Persons ObservableCollection,我已經在Person類中添加了6個成員,現在我需要從它中過濾出來並將其存儲在Person類的新ObservableCollection中,請說PersonNew謝謝..... – Pritesh 2011-05-28 10:49:15

回答

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

或者,更簡潔:

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

如果你有一些您可以使用collection view從人員收集中選擇人員的標準。

+0

不錯,這就是我所確定的需要...........非常感謝你回答....... – Pritesh 2011-05-28 11:12:46

+0

我想var PersonsNew = new ObservableCollection (Persons.Skip(3).Take(4));它應該沒有var關鍵字好吧................謝謝..... – Pritesh 2011-05-28 11:13:29

+0

正如我所說,使用'var'使代碼更簡潔 - 它不會改變它的行爲。 – 2011-05-28 15:47:50