grady
grady

Reputation: 12755

Convert generic IList<CustomType> to array?

I have an IList which contains a custom type. One of the properties of that custom type is called ID. How could I convert that without using a for loop? The array should not be of the CustomType, but if the type of ID, which is int.

Thanks!

Upvotes: 2

Views: 2200

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

Try:

sourceList.Select(i => i.ID).ToArray();

Where sourceList is your list of type IList<CustomType>.

Upvotes: 14

Related Questions