Generic Dictionary - Getting Conversion Error
- by pm_2
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?