Time for action – let's say "Hello" to your buddies

Here is the first problem:

Say we have a List of names and we want to print "Hello" in front of all the names:

  1. Copy the following code snippet as a query to the LINQPad:
    List<string> nameList1 = new List<string> (){ "Anders", "David", "James", "Jeff", "Joe", "Erik" };
    nameList1.Select(c => "Hello! " + c).ToList().ForEach(c => Console.WriteLine(c));
  2. Run the query.

The preceding code snippet will give the following output:

Time for action – let's say "Hello" to your buddies

What just happened?

The Lambda expression c => "Hello!" + c is basically creating a projection of the elements of nameList1 List and the result will be an instance of IEnumerable<string> ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.