I have a TextBoxD1.Text
and I want to convert it to an int
to store it in a database.
How can I do this?
Be careful when using Convert.ToInt32()
on a char!
It will return the UTF-16 code of the character!
If you access the string only in a certain position using the [i]
indexing operator, it will return a char
and not a string
!
String input = "123678";
^
|
int indexOfSeven = 4;
int x = Convert.ToInt32(input[indexOfSeven]); // Returns 55
int x = Convert.ToInt32(input[indexOfSeven].toString()); // Returns 7