Time for action – tagging names

Follow the given steps:

  1. Copy the following code snippet as a query to LINQPad:
    List<string> boys = new List<string> {"Anders", "Anders", "David", "James", "Jeff", "Joe", "Erik"};
    
    List<string> girls = new List<string> {"Anna", "Anzena", "Dorothy", "Jenny", "Josephine", "Julee"};
    
    List<string> nameList1 = new List<string>() {"Anders", "Anna", "Joe", "Jenny", "Anzena", "Josephine", "Erik"};
    
    Dictionary<string, string> nameMap = nameList1.ToDictionary(c => c,c=>boys.Contains(c)?"boy":"girl");
    
    nameMap.Keys.Dump("All Members");
    nameMap.Keys.Where(c => nameMap[c] == "boy").Dump("Boys");
    nameMap.Keys.Where(c => nameMap[c] == "girl").Dump("Girls");
  2. Run the query. You will see the following output:

What just happened?

The Lambda ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.