I have list of Contacts:
public class Contact
{
private string _firstName;
private string _lastName;
private int _age;
///
public List<string> FirstNames
{
get
{
return _contactList.Select(C => C.FirstName).ToList();
}
}
You want to use the Select
method, not Where
here:
_contactList.Select(C => C.FirstName).ToList();
Further, the need for the ToList()
only exists because the property
demands it. You could return an IEnumerable<string>
instead if you wanted to get rid of that.