title: Switch case and generics checking
body: <p>I want to write a function that format <code>int</code> and <code>decimal</code> differently into string</p>
  
  <p>I have this code:</p>
  
  <p>and I want to rewrite it to generics:</p>
  
  <pre><code>    public static string FormatAsIntWithCommaSeperator(int value)
      {
          if (value == 0 || (value &gt; -1 &amp;&amp; value &lt; 1))
              return "0";
          return String.Format("{0:#,###,###}", value);
      }
  
      public static string FormatAsDecimalWithCommaSeperator(decimal value)
      {
          return String.Format("{0:#,###,###.##}", value);
      }
  
  
      public static string FormatWithCommaSeperator&lt;T&gt;(T value) where T : struct
      {
          string formattedString = string.Empty;
  
          if (typeof(T) == typeof(int))
          {
              if ((int)value == 0 || (value &gt; -1 &amp;&amp; value &lt; 1))
              return "0";
  
              formattedString = String.Format("{0:#,###,###}", value);
          }
  
          //some code...
      }
  
      /// &lt;summary&gt;
      /// If the number is an int - returned format is without decimal digits
      /// &lt;/summary&gt;
      /// &lt;param name="value"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static string FormatNumberTwoDecimalDigitOrInt(decimal value)
      {
          return (value == (int)value) ? FormatAsIntWithCommaSeperator(Convert.ToInt32(value)) : FormatAsDecimalWithCommaSeperator(value);
      }
  </code></pre>
  
  <p>How can i use T in the function body?</p>
  
  <p>What syntax should I use?</p>