-1

I am a beginner and I am doing a calculator with a console application in C#, I want to know how to make a string includes all the texts and words. For example :
_ Enter the first number!
: stack
_ Error, cannot use texts in division!

So, I want to make a code like that

If (firstnumber == string) (not int or double){

Console.WriteLine("Error, cannot use texts in division");

}

Please, help me.

                                   Thanks

1 Answers1

2

I think is this you wont.

string input = Console.ReadLine();

try
{
    int firstNumber = int.Parse(input);
}
catch (Exception)
{
    Console.WriteLine("Error, cannot use texts in division");
}
Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
LeoFraietta
  • 192
  • 5
  • 13
  • 2
    It looks like a `TryParse` is better for this case. But even with `Parse` approach catching all type of exceptions is not a best idea. How about to catch only `FormatException`? – Aleks Andreev Feb 01 '19 at 19:02
  • You are right, but the question was marked as duplicate an i thing the best way is like @PilouPili post on link. – LeoFraietta Feb 01 '19 at 19:10