title: C# Dictionary Return Type
body: <p>I've got a problem with some c# code I'm writing, I'm fairly new to c# and I've had a look around and can't find a solution. </p>
  
  <p>I've got a method that returns a Dictionary, I've set the return type to object and it seems ok.</p>
  
  <pre><code>    public object loopThroughNotificationCountQueries()
      {
          var countQuery = new Dictionary&lt;string, string&gt;(); ...
  
  
          ... return countQuery;
      }
  </code></pre>
  
  <p>The problem is in the main method where I'm trying to loop through the elements returned from the dictionary.</p>
  
  <pre><code>                Notification notification = new Notification();
  
                  var countDictionary = notification.loopThroughNotificationCountQueries();
  
  
                  foreach(KeyValuePair&lt;String, String&gt; entry in countDictionary)
                  {
                      ...
                  }
  </code></pre>
  
  <p>I'm getting an error saying "Error  2   foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'"</p>
  
  <p>Is it because I'm not specifying the correct return type for a dictionary? Or is there another way of iterating through the entries in the returned object?</p>
  
  <p>Thanks for your help,
  Stephen.</p>