Dictionary

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have dictionary, ValueProvider, which has the following type.

IDictionary <String, ValueProviderResult>.

I need to get the ValueProviderResult which Key (String) is equal to
"xyz".

I have the following:
article.Id = (Guid)bindingContext.ValueProvider["Id"].ConvertTo(typeof
(Guid));

The problem is I get an error when there is no such item with key
"Id".

How can I get the value only if it exists?

Thanks,
Miguel
 
I have dictionary, ValueProvider, which has the following type.

IDictionary <String, ValueProviderResult>.

I need to get the ValueProviderResult which Key (String) is equal to
"xyz".

I have the following:
article.Id = (Guid)bindingContext.ValueProvider["Id"].ConvertTo(typeof
(Guid));

The problem is I get an error when there is no such item with key
"Id".

How can I get the value only if it exists?

Have a look at the TryGetValue() method.
 
Back
Top