Example 1
| The code is as follows: |
Copy code |
|
# Region's method of determining whether a number is used
Public bool isnumeric (string str)
{
Char [] ch = new char [str. Length];
Ch = str. ToCharArray ();
For (int I = 0; I <ch. Length; I ++)
{
If (ch [I] <48 | ch [I]> 57)
Return false;
}
Return true;
}
# Endregion
|
Example 2
| The code is as follows: |
Copy code |
|
Class IsNumeric
{
// Determine whether the string is a pure number
Public static bool IsNumber (string str)
{
If (str = null | str. Length = 0) // verify whether this parameter is null.
Return false; // Yes, False is returned.
ASCIIEncoding ascii = new ASCIIEncoding (); // instance of new ASCIIEncoding
Byte [] bytestr = ascii. GetBytes (str); // Save the string type parameter to the array
Foreach (byte c in bytestr) // traverses the content in this array
{
If (c <48 | c> 57) // determines whether it is a number.
{
Return false; // No, False is returned.
}
}
Return true; // Yes, True is returned.
}
} |
The above two instances are simple: get the character type and traverse it to determine if it is a number.