Valerie Meunier

Valerie Meunier

  • 1.6k
  • 533
  • 25.4k

how to accept int and double in same textbox?

Jan 30 2022 2:06 PM


To accept only integer in a textbox (windows forms), i use if (int.TryParse(textBox1.Text, out num) == true) with num as int and for double if (double.TryParse(textBox1.Text, out num) == true) with num as double. But how to accept together an integer and a double number in a textbox?

My solution is to use a double, so int or float or double will be accepted, but the price is that a simple integer will take 8 bytes of memory. Is that acceptable for you?



Answers (1)