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
if (str.All(char.IsDigit)) {
// String only contains numbers
}
bool result = int.TryParse("123", out var n);
using System;
namespace Help
{
class Program
{
static void Main(string[] args)
{
string text1 = "Hello";
string text2 = "29";
if (CheckInt(text1) == true) // if text 1 is a int, it's going to print : Text 1 is a int
{
Console.WriteLine("Text 1 is a int");
}
else if (CheckInt(text2) == true) // if text 2 is a int, which is the case, it's going to print : Text 2 is a int
{
Console.WriteLine("Text 2 is a int");
}
}
public static bool CheckInt(string input)
{
int number = 0;
return int.TryParse(input, out number);
}
}
}
bool *name* = int.TryParse(*name2*, out int n);