Time for action – finding all names that appear mutually exclusively

Follow the given steps:

  1. Copy the following code snippet as a query to LINQPad:
    List<string> nameList1 = new List<string> (){"Anders", "David", "James", "Jeff", "Joe", "Erik"};
    List<string> nameList2 = new List<string>() {"Erik", "David", "Derik"};
    
    //This will store the names that appear in nameList2 but not in
    //nameList1.
    var exclusiveNames = nameList2.Except(nameList1);
    foreach (var v in exclusiveNames)
    Console.WriteLine(v);
  2. Run the query. You should get the following output:
    Time for action – finding all names that appear mutually exclusively

What just happened?

The name "Derik" is present only in nameList2 and not in nameList1, so it is returned. ...

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.