C# Program to Check if a String is Numeric – Programming, Pseudocode Example, C# Programming Example
C# Console

C# Program to Check if a String is Numeric

In this program, you’ll learn  to check if a string is numeric or not in C#.

Code:  Check if a string is numeric

In the above program, we’ve a text named string which contains the string to be checked. We also have a bool value numeric which stores if the final result is numeric or not.

To check if string contains numbers only, in the try block, we use Double’s Parse() method to convert the string to a Double.

If it throws an error , it means string isn’t a number and numeric is set to false. Else, it’s a number.

Output:

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.