view raw
Leon Barkan Leon Barkan - 6 months ago 45
C# Question

How to get key object from Dictionary by key

In my application, I have a dictionary with key/value objects

Dictionary<TObject,VObject> list

To check if I have the object, I'm using a special instance of
and checking if it exists in the list.

After i get
, I need to get the original Key object (

VObject result = list[TObject]; // will return me the VObject

The original
(the key), has more values that have been initialized on the object creation and I need to do a test on them.

How can i do this?


The dictionary object contains Keys property, please see for more information.

You can run queries against this property to select the key you are looking for.

Useage with linq;

var foundKey = dictionaryObject.Keys.FirstOrDefault( * Linq Expression* );