by Edward
30 April 2010 16:57
A new feature I noticed while doing some prototyping some functionality with Visual Studio 2010, is the new overload method available for the 'String.Concat' method that takes an IEnumerable<T>. I found this to be very useful with LINQ query expressions.
Below is a simple example:
public static void Main()
{
List<Employee> employees = new List<Employee>();
employees.Add(new employees("John", "Doe"));
employees.Add(new employees("Jane", "Doe"));
employees.Add(new employees("John", "Code"));
string output = String.Concat(employees.Where(employee =>
(employee.Surname == "Doe")));
//write the output to screen
Console.WriteLine(output);
}
The Enumerable.Where extension method is called to extract the Employee objects whose 'Surname' property equals "Doe". The result is passed to the Concat<T>(IEnumerable<T>) method and displayed to the console.