score:1

Accepted answer

You could save your in-memory users in a KeyedCollection.

score:2

Assuming the primary key is a reference type, you'd only be storing a reference to the primary key twice.

Have you tried using Dictionary<,> and found it doesn't work well enough? It's certainly the most natural solution. KeyedCollection<,> (suggested by Mark) would certainly work too, but requires you to derive from the class - and I wouldn't like to guarantee it'll actually save any memory. (You'd need to know the implementation details - it could easily just use a Dictionary internally, for example.)


Related Articles