Hello, 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!
Hello, 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!
Hi there.
Try:
sourceList.Select(i => i.ID).ToArray();
Where sourceList
is your list of type IList<CustomType>.
Cheers. Jas.
Hi - Something like this
IList<x> xList = new List<x>{ new x() { ID = 1, Name = "Alice"}, new x() { ID = 2, Name = "Bob"}};
int[] myInts = xList.Select(myItem => myItem.ID).ToArray();