.NET: Are Dictionary values stored by reference or value

NSjonas picture NSjonas · Oct 25, 2012 · Viewed 27.1k times · Source

I have a Dictionary<int, Product>. If the same Product is added to more than one key is an new instance of that object stored for each key? Or just a reference to the original object?

This collection is very large and each product will have between 1-10 Keys to it. My primary concern is memory allocation.

Answer

zmbq picture zmbq · Oct 25, 2012

If Product is a reference type (class and not struct), only a reference will be stored.