Recently, I was working on a website written in vb.net. A student once asked me a question, saying that the program always throws the error "the conversion from the string" aa "to the type" Double "is invalid. I used to look at it as a database operation function. I first thought of assigning an error to the parameter, causing a database error. Then there was a database query error, but after searching for the database for half a day, I found that the database write operation was not correct. I was puzzled. The database did not have a Double field, but it throws this error, it's strange.
Later, I went through line-by-line debugging and saw that the program was mistakenly connected to a numeric variable and a numeric variable. I will not post the original program, which is simplified as follows:
Dim iTemp As Integer = 3
Dim strTemp As String = "aa"
Response. Write (strTemp + iTemp)
Such logical statements are often written in C # and written in C # as follows:
String strTemp = "aa ";
Int iTemp = 3;
Response. Write (strTemp + iTemp );
In C #, the same program will not throw the error "the conversion from the string" aa "to the type" Double "is invalid.
What is the difference between VB.net and C?
When a string type variable is added to a numeric type variable, C # implicitly converts the numeric type variable to the numeric type and then connects the numeric type data, however, VB.net converts a numeric type to a numeric type. In this conversion process, the system first converts both numeric and numeric types to a more precise data type (Double) conversion. However, the data converted from an integer to a Double type will not go wrong, but the data converted from a numeric type to a Double type will go wrong, the error "invalid conversion from the string" aa "to the type" Double "will be thrown.
Vb.net has the Concatenation Operators "&" and "+"
+ Add a connector. If the two operands are strings, connect these two operands into a String. Otherwise, process them by the plus sign.
& The connector forcibly converts the operation data to a String and then performs the join operation.