I am parsing a file and I would like to store it in a lookup structure in a way that I can lookup with two keys.
I have a User Entity
that has name, email
and id
, types are irrelevant.
I would like to store it in a Dictionary<User, id>
so I can get the user id by looking up with User.
I also want the other way around, ie : Dictionary<Id, User>
I can create two structures and do the lookup. That s easy. I d like to do it with a single structure.
I am curious if I can do this with a single structure
I was thinking that I can do:
Dictionary<User, User>
, then implement a IEqualityComparer<User>
Is there a better way to do this?
What would be the best practice to implement IEqualityComparer?