number or not HELP?

Console.WriteLine("");
string c = Console.ReadLine();
double value;
if (double.TryParse(c, out value))
{
Console.WriteLine("Okey we go back i guess");
}

double newnumber = Convert.ToDouble(Console.ReadLine());
Numbers.Add(newnumber);
Console.WriteLine("");
string c = Console.ReadLine();
double value;
if (double.TryParse(c, out value))
{
Console.WriteLine("Okey we go back i guess");
}

double newnumber = Convert.ToDouble(Console.ReadLine());
Numbers.Add(newnumber);
how to check of the value is a number or not ?
2 Replies
mtreit
mtreitβ€’3y ago
When you call TryParse it will return true if it's a valid number or false if it's not.
eult πŸ‡΅πŸ‡ΈπŸ‡΅πŸ‡Έ

Console.WriteLine("");
string c = Console.ReadLine();
if (int.TryParse(c, out var result))
{
Console.WriteLine($"Thanks for giving me the following number: {result}!");
}
else
{
Console.WriteLine("You didn't give me a valid number :c");
}

Console.WriteLine("");
string c = Console.ReadLine();
if (int.TryParse(c, out var result))
{
Console.WriteLine($"Thanks for giving me the following number: {result}!");
}
else
{
Console.WriteLine("You didn't give me a valid number :c");
}
works πŸ˜‰
Want results from more Discord servers?
Add your server