Vb. The division operator in net and the division operator in C #

Source: Internet
Author: User
Tags integer division

Vb. The Division operators in net have two:/(floating-point division), \ (integer division)

The division operator in C # has only one:/(Division)

Vb. The division operator in net differs greatly from the division operator in C # , and is differentiated when used.

Introduction to the division operator in vb.net (from MSDN):

/(Floating point Division): divides two numbers and returns the result expressed as a floating-point number.

The data type of the resulting result depends on the type of the operand. The following table shows how to determine the data type of the result.

Operand data type

Result data type

Two expressions are integer data types (SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong) Double
One expression is a single data type and the other expression is not Double

Single

One expression is a Decimal data type and the other expression is not single or Double

Decimal

Either expression is a Double data type Double
Any integer numeric expression will be extended to Double before the division is performed. If you assign the result to an integer data type, Visual Basic attempts to convert the result from a Double to this type. If the result does not fit the type, an exception is thrown. If DivisorOr DividendThe result of the calculation equals nothing, it is treated as zero. \ (integer division): divides two numbers and returns the result expressed as an integer. The following table determines the data type of the result. Note that this table is symmetric, and for a given operand data type combination, the result data type is the same regardless of the order of the operands.
Boolean SByte Byte Short UShort Integer UInteger Long ULong
Boolean Boolean SByte Short Short Integer Integer Long Long Long
SByte SByte SByte Short Short Integer Integer Long Long Long
Byte Short Short Byte Short UShort Integer UInteger Long ULong
Short Short Short Short Short Integer Integer Long Long Long
UShort Integer Integer UShort Integer UShort Integer UInteger Long ULong
Integer Integer Integer Integer Integer Integer Integer Long Long Long
UInteger Long Long UInteger Long UInteger Long UInteger Long ULong
Long Long Long Long Long Long Long Long Long Long
ULong Long Long ULong Long ULong Long ULong Long ULong

If any of the two operands of the \ operator is a Decimal, single, or Double, Visual Basic attempts to convert it to long before the operation, and the result data type of the operation is long. If Option Strict is on, a compiler error is generated. If Option Strict is Off, OverflowException may be generated if the value exceeds the range of the Long data type (Visual Basic). The conversion to Long also obeys "four homes six into 50% pairs". If the divisor or dividend evaluates to nothing, it is treated as zero.

An introduction to the division operators in C # (from MSDN):

/(Division): divides two numbers and returns the data type with high precision in the data type of divisor and dividend.

Before the division is performed, the compiler unifies the data types of the divisor and dividend into high precision data types in both types. The type of the result of the returned operation is also a data type with high precision in both types. For example, the result of dividing two integers is always an integer. Divides an integer and a double, returning the result to a double type. However, it is important to note that double and decimal do not perform arithmetic operations directly, they must first be explicitly unified before they can be performed, and double and decimal cannot be directly operated because there is no implicit type conversion between the two.

Vb. The division operator in net and the division operator in C #

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.