Skip to content

Instantly share code, notes, and snippets.

@MessiDaGod
Created July 27, 2022 17:21
Show Gist options
  • Save MessiDaGod/1d689c6c388d656bfcad836899ceb3de to your computer and use it in GitHub Desktop.
Save MessiDaGod/1d689c6c388d656bfcad836899ceb3de to your computer and use it in GitHub Desktop.
Is a field/type numeric C#
private static HashSet<Type> NumericTypes = new HashSet<Type>
{
typeof(decimal), typeof(byte), typeof(sbyte), typeof(double)
,typeof(short), typeof(ushort), typeof(Single), typeof(UInt16)
,typeof(Int16), typeof(Int32), typeof(UInt32),typeof(UInt64)
,typeof(Int64), typeof(float)
};
public static bool IsNumeric(Type type)
{
return NumericTypes.Contains(type) ||
NumericTypes.Contains(Nullable.GetUnderlyingType(type));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment