C# dictionary uniqueness for sibling classes using IEquatable<T>

Posted by anthony on Stack Overflow See other posts from Stack Overflow or by anthony
Published on 2010-04-22T20:53:03Z Indexed on 2010/04/22 21:23 UTC
Read the original article Hit count: 389

Filed under:
|
|
|
|

I would like to store insances of two classes in a dictionary structure and use IEquatable to determine uniqueness of these instances. Both of these classes share an (abstract) base class. Consider the following classes:

abstract class Foo
{
   ...
}

class SubFoo1 : Foo
{
   ...
}

class SubFoo2 : Foo
{
   ...
}

The dictionary will be delcared: Dictionary<Foo, Bar>

Which classes should be declared as IEquatable? And what should the generic type T be for those declarations? Is this even possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Identity