Nathan McKaskle Nathan McKaskle - 2 months ago 8
C# Question

Converting an Object List to a String List

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);
}

Answer

Yes you can use LINQ. Like this:

List<string> managerList = matchedManager.Select(m => m.FullName).ToList();