namespace Dic
{
public class Key
{
string name;
public Key(string n) { name = n; }
}
class Program
{
static string Test()
{
Key a = new Key(
In order to use your own classes as dictionary keys, you should override GetHashCode and Equals. Otherwise it will use the memory address to check for equality.
public class Key
{
string name;
public Key(string n) { name = n; }
public override int GetHashCode()
{
return name.GetHashCode();
}
public override bool Equals(object obj)
{
var other = obj as Key;
if( other == null )
return false;
return name == other.name;
}
}