Cast from one generic IDictionary to another

P

pierre.k

Hello,
how can I do a cast like
IDictionary<int, string> as IDictionary<object, string> ?

Thanks in advance for your help,
pierre.k
 
S

Stanimir Stoyanov

You can't just cast a generic dictionary with a different key data type. You
can however create the second dictionary, copy the original keys to an int[]
using the Keys.CopyTo method, go through them and populate the new
dictionary with the old data.

Stanimir Stoyanov | www.stoyanoff.info
 

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

Top