// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class Person { private string name; private string address; public Person(string name, string address) { this.name = name; this.address = address; } public string Name { get { return name; } } public string Address { get { return address; } } public override string ToString() { return name + "/" + address; } public override bool Equals(object obj) { return obj.GetType() == typeof(Person) && ((Person)obj).Name == name; } public override int GetHashCode() { return name.GetHashCode(); } } public class Program { public static void Main(string[] args) { List x = new List(); x.Add(new Person("A A", "aa aa aa aa")); x.Add(new Person("B B", "bbb bbb bbb")); x.Add(new Person("C C", "cccc cccc")); List y = new List(); y.Add(new Person("C C", "cccc cccc")); y.Add(new Person("D D", "ddddd")); Console.WriteLine("x:"); foreach(Person p in x) { Console.WriteLine(" " + p); } Console.WriteLine("y:"); foreach(Person p in y) { Console.WriteLine(" " + p); } Console.WriteLine("x except y:"); foreach(Person p in x.Except(y)) { Console.WriteLine(" " + p); } } } }