csharp how to check string is number
Code Example - csharp how to check string is number
string s1 = "123";
string s2 = "abc";
bool isNumber = int.TryParse(s1, out int n); // returns true
isNumber = int.TryParse(s2, out int n); // returns false
csharp see if string is int
bool result = int.TryParse("123", out var n);
is number csharp
var isNumeric = int.TryParse("123", out int n);
csharp check if string is all numbers
if (str.All(char.IsDigit)) {
// String only contains numbers
}
verify if number csharp
var isNumeric = int.TryParse("123", out int n);