If I want to use objects as the keys for a Dictionary
, what methods will I need to override to make them compare in a specific way?
Say I have a a class which has properties:
class Foo {
public string Name { get; set; }
public int FooID { get; set; }
// elided
}
And I want to create a:
Dictionary<Foo, List<Stuff>>
I want Foo
objects with the same FooID
to be considered the same group. Which methods will I need to override in the Foo
class?
To summarize: I want to categorize Stuff
objects into lists, grouped by Foo
objects. Stuff
objects will have a FooID
to link them to their category.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…