Does the text box save all text as a long string or string?

I have a brief discussion about my teammate about this. He says that if I enter a number in the text box and try to use the value later using textbox.text or val (textbox.text), I will not need to parse the integer value. According to him, if the value of the text attribute is the whole number, you can directly get the value as an integer, not a string.

So, if I have textBox1.Text = "12345", then the next time, if I use intABC = textBox1.Text, it does not throw an error. It is right? Does C # or another .Net language use this implicit conversion? In addition, will the code be stored "12345"as a string or as an integer? And how much memory will this value take, 5 bytes for 5 characters or 2 bytes for an integer?

+3
source share
4 answers

TextBox.Text saves the text as a simple line, it does not care about the real "value" of the line.

Then, if you want to return your number, you need to parse the string, so neither explicit nor explicit casting to int is allowed (or, better, it will throw an exception if you do this ...).

, UNICODE (UTF-16), , 2 4 ( ).

( - ..), :

int numBytes = Encoding.Unicode.GetByteCount(stringToMeasure);

, , , .

+14

, , NumericUpDown.
/ () Value.

A NumericUpDown element contains a single numeric value that can be increased or decreased by pressing the up or down button on the control. The user can also enter a value if the ReadOnly property is not set to true.

+2
source

Regarding your question about other languages; if option strict is not enabled, VB.NET will allow this. It will also allow this assignment if the input is not completely numeric, but as a result an exception is thrown at runtime.

+2
source

All Articles