How to check if a string is a valid number in C#

1 Answer

0 votes
using System;

class Program {
    static void Main(string[] args)
    {
        int n;
        string s = "3920";
        
        bool isValidNumeber = int.TryParse(s, out n);
        
        Console.WriteLine(isValidNumeber);
        Console.WriteLine(n);
    }
}
 
 
 
/*
run:

True
3920
 
*/

 



answered May 5, 2024 by avibootz
...