// 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; namespace E { public class A { private string s; public A(string s) { this.s = s; } } public class B { private string s; public B(string s) { this.s = s; } public override bool Equals(object o) { if(o is B) { return s.Equals(((B)o).s); } else { return false; } } public override int GetHashCode() { return s.GetHashCode(); } } public class MainClass { public static void Main(string[] args) { List la = new List(); A a = new A("x"); la.Add(a); la.Add(new A("y")); Console.WriteLine(la.Remove(a)); Console.WriteLine(la.Remove(new A("y"))); List lb = new List(); B b = new B("x"); lb.Add(b); lb.Add(new B("y")); Console.WriteLine(lb.Remove(b)); Console.WriteLine(lb.Remove(new B("y"))); } } }