Recently, I was working on a website written in VB.net. A colleague 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 "the conversion from the string" AA "to the type" double "is invalid" will be thrown.
The error was found, but I do not know why VB.net and C # are different in handling this problem? Take a good look.