Is Numeric Type - CSharp System

CSharp examples for System:Type

Description

Is Numeric Type

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/* www  . j av a 2s. c  om*/

public class Main{
    public static bool IsNumericType(this Type type)
      {
         return type.IsInteger() || type.IsFloatingPoint();
      }
    public static bool IsInteger(this Type type)
      {
         return type.IsEnum ||
                type == typeof (int) || type == typeof (uint) || type == typeof (short) || type == typeof (ushort) ||
                type == typeof (byte) || type == typeof (sbyte) || type == typeof (long) || type == typeof (ulong);
      }
    public static bool IsFloatingPoint(this Type type)
      {
         return type == typeof (float) || type == typeof (double);
      }
}

Related Tutorials