Zeeshan Hirani

Senior .net Developer

ConvertAll delegate

Today I had the need to convert a list of objects in a collection to a list of different objects in a collection. Although its a pretty simple use case which would not require too much manual code to do it. But surely enough I got introduced to a build in method Convert that is available on List<T>. Convert pretty much tells you by name what its purpose is. It converts one collection to another collection by taking a delegate which specifies how to to transform one object to another. Here is an example that shows how to use ConvertAll.

image

Comments

Will Sahatdjian said:

Is there some performance advantage to doing this over using persons.Select(p => new Employee { .... } ) ?

# May 10, 2008 10:58 AM

zhirani said:

Good question. I am not sure. I guess forgot about select operator. Infact i would prefer select cuz its more intitutive.

# May 10, 2008 3:41 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)