Parts of BindingList to string array
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>();
精彩评论