开发者

Parts of BindingList to string array

开发者 https://www.devze.com 2023-03-23 12:06 出处:网络
I\'m am using the BindingList to populate some controls. On part of a form I need to use some of the data stored within the BindingList to create and array.Say I have BindingList<CEmployee> and

I'm am using the BindingList to populate some controls.

On part of a form I need to use some of the data stored within the BindingList to create and array. Say I have BindingList<CEmployee> and wanted to retrieve all CEmployee.Surnames into a string array how would I go about this without looping through each CEmployee in the BindingList?

开发者_JAVA百科Regards

Taff


You can use LINQ to query the Surnames:

var surnames = from employee in myBindingList select employee.Surname;

If you need it as an Array, you can use the ToArray method of the result:

string[] surnamesArray = surnames.ToArray<string>();
0

精彩评论

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