Windows Vista Forums

Cast from one generic IDictionary to another
  1. #1


    pierre.k Guest

    Cast from one generic IDictionary to another

    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



    "pierre.k" <petr.krebs@xxxxxx> wrote in message
    news:91380878-51a9-42ac-88b5-66d61c6e802a@xxxxxx

    > Hello,
    > how can I do a cast like
    > IDictionary<int, string> as IDictionary<object, string> ?
    >
    > Thanks in advance for your help,
    > pierre.k

      My System SpecsSystem Spec

  2. #2


    Stanimir Stoyanov Guest

    Re: Cast from one generic IDictionary to another

    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

    "pierre.k" <petr.krebs@xxxxxx> wrote in message
    news:91380878-51a9-42ac-88b5-66d61c6e802a@xxxxxx

    > Hello,
    > how can I do a cast like
    > IDictionary<int, string> as IDictionary<object, string> ?
    >
    > Thanks in advance for your help,
    > pierre.k

      My System SpecsSystem Spec

Cast from one generic IDictionary to another problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of cast between c++ and c# ? Scotty .NET General 3 09 Apr 2010
Type cast Joachim Meyer PowerShell 1 26 Aug 2008
Converting String Pairs to IDictionary? coconet .NET General 3 30 Apr 2008
Specified cast is not valid RW .NET General 3 06 Mar 2008
meaning of this cast ? Leo Tohill PowerShell 3 15 Nov 2007