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);
2 Replies
When you call TryParse it will return true if it's a valid number or false if it's not.
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");
}