title: How to declare a generic variable inside a generic method?
body: <p>I would like to know if it is possible to declare a generic variable inside a generic method. In the following code, I am trying to make "results" a generic variable but I am having a hard time doing so. Therefore, I would appreciate any help on this. Thanks in advance</p>
  
  <pre><code>    public static T GetSQLResults&lt;T&gt;(string StoredProcName, Dictionary&lt;string, string&gt; StoredProcParameters)
      {
          var results;
  
          using (SqlConnection conn = new SqlConnection(Settings.ConnStringDb))
          {
              using (SqlCommand cmd = new SqlCommand(StoredProcName, conn))
              {
                  cmd.CommandType = CommandType.StoredProcedure;
                  foreach (var param in StoredProcParameters)
                  {
                      cmd.Parameters.AddWithValue(param.Key, param.Value);
                  }
  
                  conn.Open();
                  if (typeof(T) == typeof(Boolean))
                  {
                      results = cmd.ExecuteReader().HasRows;
                  }
                  else if (typeof(T) == typeof(DataTable))
                  {
                      results.Load(cmd.ExecuteReader());
                  }
  
                  //results.Load(cmd.ExecuteReader());
                  conn.Close();
              }
  
              return (T)Convert.ChangeType(results, typeof(T));
          }
      }
  </code></pre>