Dictionary

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
 
J

Jeff Johnson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top