title: Find specific value in HttpContext.Current.Cache
body: <p>I am having some trouble with this and can't quite understand why I can't get a specific value from my collection stored in the code below...</p>
  
  <pre><code>public Dog Get(string name)
      {
          Dog dog = null;
  
          var context = HttpContext.Current;
  
          if (context.Cache[CacheKey] != null)
          {
              System.Collections.IDictionaryEnumerator en = context.Cache.GetEnumerator();
  
              while (en.MoveNext())
              {
                  if (en.Key.ToString() == "AnimalStore")
                  {
                      // I would like to use a foreach loop to look for a specific dog here but I get an error!
                      // foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
                      foreach (var item in en.Value)
                      {
                         // en.Value contains two Dog objects with data but I can't get at them or their properties....
                      }
                  }
  
              }
  
              //dog = (Dog)context.Cache[CacheKey];
          }
  
          return dog;
      }
  </code></pre>
  
  <p>foreach statement cannot operate on variables of type 'System.Collections.IDictionaryEnumerator' because 'System.Collections.IDictionaryEnumerator' does not contain a public definition for 'GetEnumerator'    </p>
  
  <p>Could someone else explain why I can't just loop through my array to get Dog.name and do something like this: //return dogs.Find(p => p.name == name);  This is quite a confusing concept to me so I appreciate the help in understanding....</p>