[Getting Started] C # vs VB. NET which is better?

Source: Internet
Author: User
When people who are new to. NET are faced with the language they choose, they often ask C # and VB. NET which is better? Which is faster?

In essence, any programming languages supported by. NET are eventually translated into il code, and their operating mechanisms are the same. In this way, it seems that all languages running on. NET Framework have no difference except syntax. In fact, each language provides additional features or restrictions. Different compiler implementations also bring about differences.

Today, when I was reading a book (professional C # Chinese Version), I saw a small difference between C # and VB. NET compilers:

It is also a + operator, and C # will be translated into IlAddCommand:

Public new int add (INT val1, int val2)

{

Return val1 + val2;

}

While VB. NET is translatedAdd. ovfCommand.
Public shadows function add (byval val1 as integer, byval val2 as integer) as integer

Return val1 + val2

End Function



SoAddCommands andAdd. ovfWhat is the difference between commands. I checked msdn:

Add. VOF: Adds two unsigned integer values, performs an overflow check, and pushes the result onto the evaluation stack.

Overflowexception is thrown if the result is not represented in the result type.

The main difference is that the latter will generate more local code to execute the overflow check, and overflowexception will be thrown if overflow occurs. The disadvantage is that the execution speed is slow, but the benefits are that the code is safer :)

Therefore, the commands generated by some code C # compilers during the generation of Il will run faster, while the Il code generated by the VB. NET compiler is safer.Advantages and disadvantages :)

In fact, whether or not to perform the overflow check can be configured (the above is only the default settings of C # and VB. NET), set in the Project Properties dialog box:

 

Or through the compiler/Checked[+ |-] Option can also be used to specify whether to check for value overflow.

In addition, C # can also useCheckedAndUncheckedKeyword to specify whether to check the value overflow, such

Z = checked (short) (x + y ));

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.