// 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() : this("")
{
}
public A(string s)
{
this.s = s;
}
public string S
{
get
{
return s;
}
set
{
this.s = value;
}
}
public override string ToString()
{
return s;
}
}
public class B
{
private string s;
public B() : this("")
{
}
public B(string s)
{
this.s = s;
}
public string S
{
get
{
return s;
}
set
{
s = value;
}
}
public override string ToString()
{
return s;
}
public override bool Equals(object o)
{
if (o is B)
{
if (s == ((B)o).S)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public override int GetHashCode()
{
return s.GetHashCode();
}
}
public class MainClass
{
public static void Main(string[] args)
{
List lst1 = new List();
lst1.Add(new A("test"));
Console.WriteLine(lst1.Contains(new A("test")));
List lst2 = new List();
lst2.Add(new B("test"));
Console.WriteLine(lst2.Contains(new B("test")));
}
}
}