if I have int number in nominator, I will do one method from my1.cs, if I have double number in nominator/denominator I will do method from another class called my2.cs . How I may code IF,
if (number = int) {//; bla bla bla...}
OR
if (number = double) {//; bla bla bla...}
How to code this if-statement: if (numerator.GetType==int){...} ?
The main trouble is in this: I read nominator and denominator from textbox, with var dr1 = textBox1.Text.Split(‘/’); ! split, but how i can gettype from string ???
or
The former is usually better.
EDIT:
Нou say the problem is parsing numbers from string representation. I’m afraid, the best approach here is to call
type.TryParseand check if given string can be parsed as a number of given type.E.g.
Note that all
ints can be parsed asdoubles, so you need to try to parse token asintbefore trying to parse it as `double.