Generic Dictionary - Getting Convertion 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:23 UTC
Read the original article
Hit count: 175
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