Search code examples
c#interopidictionary

COM Interop IDictionary - How to retrieve a value in C#?


using: VS2008, C#

I have a COM dll I need to use in a .NET project. In there I have a class with a method that returns an IDictionary object. IDictionary is defined in the COM dll so I'm not sure if it's the same as IDictionary in .NET.

My problem: I know the dictionary keys and I want to retrieve the values. The documentation for this COM dll gives code in Classic ASP like

someValue = oMyDictionary.someDictionaryKey

My Question: How do I retrieve the values for the specific keys in C#?

When I create the IDictionary object in C# like this:

IDictionary oDictConfig = oAppConfig.GetOptionsDictionary("");

VS2008 reckons this dictionary object (interface) has the following methods and properties:

Cast<>
Count
Equals
GetEnumerator
GetHashCode
GetMultiple
GetType
let_Value
OfType<>
Prefix
PutMultiple
ToString

Sorry if this is a silly question, but I can't see how to retrieve a value passing a key.


Solution

  • IDictionary has an Item property among its members that you access via [ ].

    var obj = oDictConfig[key];