A small difference between VB.net and C # string connection

Source: Internet
Author: User

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.

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.