Home
Manage Your Code
Snippet: IsCharNumeric (C#)
Title: IsCharNumeric Language: C#
Description: A function that checks whether or not a char is numeric. Views: 556
Author: Berin Iwlew Date Added: 3/28/2008
Copy Code  
1/// <summary>

2/// Checks to see whether or not a Char is Numeric

3/// </summary>

4/// <param name="numericChar">The Char to check</param>

5/// <returns>True if numeric, False if not</returns>

6public static bool IsCharNumeric(char numericChar)
7{
8    int charCode = Convert.ToInt32(numericChar);
9    if (charCode > 47 && charCode < 58)
10        return true;
11    else
12        return false;
13}
Usage
bool isNumeric = IsCharNumeric('1'); // returns true
bool isNumeric = IsCharNumeric('a'); // returns false