title: Using Generics to Multiply Integers
body: <p>I have a class called GenericItem (first time using generics), suppose i wanted to multiply two items if they were of the type integer, as you can see I am trying it in the method <code>returnCounterMultiply</code>, but it does not allow me to multiply them although i am trying to convert them and also checking if they are of type integer.</p>
  
  <pre><code>namespace Components
  {
      public class GenericItem&lt;T&gt;
      {
          private T data;
          private T counter;
  
          public T Data
          {
              get { return data; }
              set { data = value; }
          }
  
          public GenericItem(){}
          public GenericItem(T _data)
          {
              data = _data;
          }
  
          public T returnCounterMultiply(T value)
          {
              int c = 0;
              int d = 0;
              if (counter.GetType() == typeof(int) &amp;&amp; value.GetType() == typeof(int))
              {
                //cant multiply two of type T, why if i am converting to int?.
                 return (T)Convert.ChangeType(counter, typeof(Int32)) * (T)Convert.ChangeType(value, typeof(Int32));
              }
              return value;
          }
  
      }
  }
  </code></pre>
  
  <p>I would appreciate some explanation on this as this is the first time I am working on it (this is just a sample class for understanding this <a href="http://msdn.microsoft.com/en-us/library/0x6a29h6.aspx" rel="nofollow">GENERICS INTRO</a> and this <a href="http://msdn.microsoft.com/en-us/library/sz6zd40f.aspx" rel="nofollow">GENERICS CLASSES</a>, but still having trouble understanding it.</p>