1

If I have a list of objects that have a property, how can I extract a list of of all of those properties?

IE given the following object

class C{
    public string name{get;set;}
}

and a list of C, how can I get a list of C.Name?

1
  • You mean to select all the names? Perhaps using LINQ? Commented Jul 25, 2014 at 21:13

1 Answer 1

14
ListOfC.Select(c => c.name).ToList();

Select is a transform function, it returns a new IEnumerable based on the selector it is given. As you specifically want a List, you need to cast it to a List afterwards.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.