Home
Manage Your Code
Snippet: Check if string is numeric (C#)
Title: Check if string is numeric Language: C#
Description: Checks to see whether or not a given string is made of all numeric chars Views: 168
Author: sl prince Date Added: 2/27/2008
Copy Code  
1 public static bool CheckIfNumeric(string myNumber)
2        {
3            bool IsNum = true;
4            if (String.IsNullOrEmpty(myNumber)) return false;
5            for (int index = 0; index < myNumber.Length; index++)
6            {
7                if (!Char.IsNumber(myNumber[index]))
8                {
9                    IsNum = false;
10                    break;
11                }
12            }
13            return IsNum;
14        }