title: Generic Method always returning NULL
body: <p>I have a generic method (already developed by another developer way back) in my project for fetching cache; though I have values for the key the method still returns <code>NULL</code>.</p>
  
  <p>Please take a look on the code:</p>
  
  <pre><code>public static C GetFromCache&lt;C&gt;(string key) where C : class     
      {     
         if (cache != null)
         {
            var testCache = cache.Get(key); // This variable is getting results
            C p = cache.Get(key) as C; this point value of 'p' is NULL
            return p; 
          }
  
          return null;
      }
  </code></pre>
  
  <p>method call:</p>
  
  <pre><code>var lstCheck = ClassName.GetFromCache&lt; List&lt; int &gt;(key);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VqFCQ.png" rel="nofollow noreferrer" title="Debugger screenshot">Debugger screenshot</a></p>