Generic Dictionary - Getting Conversion Error

Posted by pm_2 on Stack Overflow See other posts from Stack Overflow or by pm_2
Published on 2010-06-17T13:17:36Z Indexed on 2010/06/17 13:53 UTC
Read the original article Hit count: 150

Filed under:
|
|

The following code is giving me an error:

        // GetDirectoryList() returns Dictionary<string, DirectoryInfo>
        Dictionary<string, DirectoryInfo> myDirectoryList = GetDirectoryList();

        // The following line gives a compile error
        foreach (Dictionary<string, DirectoryInfo> eachItem in myDirectoryList)

The error it gives is as follows:

Cannot convert type 'System.Collections.Generic.KeyValuePair<string,System.IO.DirectoryInfo>' to 'System.Collections.Generic.Dictionary<string,System.IO.DirectoryInfo>’

My question is: why is it trying to perform this conversion? Can I not use a foreach loop on this type of object?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics