I have a problem with the C # code I'm writing, I'm pretty new to C #, and I looked around and can't find a solution.
I have a method that returns a dictionary, I set the return type to the object, and it looks fine.
public object loopThroughNotificationCountQueries() { var countQuery = new Dictionary<string, string>(); ... ... return countQuery; }
The problem lies in the main method in which I try to iterate over elements returned from a dictionary.
Notification notification = new Notification(); var countDictionary = notification.loopThroughNotificationCountQueries(); foreach(KeyValuePair<String, String> entry in countDictionary) { ... }
I get the error message "Error 2 foreach statement cannot work with variables of type" object "because" object "does not contain a public definition for" GetEnumerator "
Is it because I am not specifying the correct return type for the dictionary? Or is there another way to repeat the entries in the returned object?
Thanks for all your help, Stephen.
source share