October 10th, 2012, 02:53 PM
Lambda expression to get a list of members from a list of objects?
I don't even know how to come up with a good title for this question.
I am using VS 2008. I have a little user control that has a method whose argument is of type List<String>. I have a list of objects (call it MyObjectList, of type List<MyObject>) whose definition includes one String member (call it myString). I want to get a List<String> that contains all of the myString strings from MyObjectList. Of course, I can write a little loop that walks through MyObjectList, adding every myString value to a List<String> object. But I am trying to be as modern as I can. With the advent of lambda expressions, I think there must be a better way to do this. Is there? If so, how? And is the answer any different in VS 2012?
Thanks very much!
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!