Assume the following class:
class Person
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
Lets say that I have a list or an array of Person object. Is there a way using LINQ to retrieve FirstName property from all the array elements and return an array of string. I have a feeling that I have seen something like that before.
Hope that the question makes sense.
Sure, very easily:
Unless you really need the result to be an array though, I’d consider using
ToList()instead ofToArray(), and potentially just leaving it as a lazily-evaluatedIEnumerable<string>(i.e. just callSelect). It depends what you’re going to do with the results.