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 ));