-1

What's a better way to write the following? Can I do it with a Lambda expression?

List<string> managerList = new List<string>();
foreach (Manager m in matchedManager)
{
    managerList.Add(m.FullName);
}
0

1 Answer 1

7

Yes you can use LINQ. Like this:

List<string> managerList = matchedManager.Select(m => m.FullName).ToList();
Sign up to request clarification or add additional context in comments.

4 Comments

I thought so, trying to figure out why I'm getting Object reference not set to an instance of an object errors on both.
@NathanMcKaskle Are you sure matchedManager is non-null?
Positive, I checked that.
you may have null items in matchedManager ... try matchedmanager.Where(i=>i!=null).Select(m=>m.FullName)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.