c# - How can I access a Dictionary through a key hashcode? -
i have dictionary that: dictionary<mycompositekey, int> clearly mycompositekey class designed implements iequalitycomparer , has gethashcode method. as far know, dictionary uses key's hash access value, here's question: while can access value via dict.trygetvalue(new mycompositekey(params)) , wanted rid off new overhead on each access. for reason wondering if there's way access value directly key's hash (which can compute lower overhead). there no way that. note hash collisions may occur, there many keys in dictionary<,> matching given hash. need equals find out (if any) correct. you talk new overhead. sure significant in case? if is, consider making mycompositekey immutable struct instead of class . might faster in cases, eliminating need garbage collector remove "loose" keys memory. if mycompositekey struct , expression new mycompositekey(params) loads params onto call stack (or cpu registers or whatev...