Conversion between numeric strings and values
First of all, we have to understand what is a numeric string. We know that in C #, the string is represented by a number of characters contained in a pair of double quotes, such as "123". "123" is relatively special, because the characters that make up the string are numbers, such a string is a numerical string. In our eyes, this is a string of characters, but the computer only thinks it is a string, not a number. Therefore, when we are at some point, when entering a value, we convert a string into a value; at other times, we need the opposite conversion. Converting numeric values into a string very simple because each class has a void toString () method. All numeric Void toString () methods can convert data to a numerical string. Such as 123.TOSTING () will result in a string "123". So in turn, what should I do if the numeric string is converted into a value? Let's take a closer look, you will find a Static Parse () function. This function is used to convert a string into a corresponding value. We use a float type to convert as an example: float f = float.parse ("543.21"); its result f is 543.21F. Of course, other numerical types can also be converted using the same method, and the following examples can more clearly describe the method of conversion:
Private void teststringvalue () {float f = 54.321f; string str = "123"; this.textBox1.text = ""; this.textBox1.AppendText ("f =" f.toString () "/ n") ; IF (int.Parse (STR) == 123) {this.TextBox1.AppendText ("Str Convert to int successfully.");} Else {this.textbox1.appendtext ("Str Convert to int fix.");} } operation result:
F = 54.321str Convert to int surpassfully.