The conversion from string "XX" to type "Double" in the VB-VB.NET is invalid

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.