C# IsNumeric Equivalent
Blog Date 22 July 2021
public static Boolean IsNumeric(string fromthis)
return Regex.IsMatch(fromthis, "^[0-9]+$");
In their perpetually infinite wisdom Microsoft's C# shares many many similarities and functions with their long historied VB. It did not take me long to move over to C# from VB which I had been using for many years.
However one key function did not make the swap from C# to VB. IsNumeric. I have precisely zero idea as to why not. If I were tortured I'd venture a guess that some heathen somewhere expected *real* programmers would be able to write their own code to do this. Pffffft.
Me? I just wanted to ensure that a particular string only contained numbers and nothing but numbers. IsNumeric did that without any thinking and now MS made me think, thinking hurts.
In the above example I have merely used the simplest of regex examples in a Boolean function. The Regex ensures all characters in the string are numbers. If they are, return true, if there's a random not-a-number character return false.
Got a coding project? Contact email@example.com
Add a RELEVANT link
Upload an image