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

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. NET and the division operator in

Division operators in C #

There is a big difference, the use of attention to distinguish.

About

vb.net

An introduction to the division operator in

Excerpt 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 (

,

,

,

,

,

,

,

)

Double
An expression of

p> data type, while another expression is not

single

One expression is

Data type, and another expression is not

or

Decimal

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

Divisor

Or

Dividend

The calculated result equals

, 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 one of the \ operator two operands is

Or

, Visual Basic attempts to convert it to a

, 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

Divisor

Or

Dividend

The result of the calculation equals nothing, it is treated as zero.

About

C#

An introduction to the division operator in

Excerpt 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.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
The division operator in C # and the division operator in vb.net

This address: http://www.paobuke.com/develop/c-develop/pbk23458.html






Related content C # using regular expressions to crawl site Information Example C # SqlHelper application Development Learning C # using regular expressions to implement the initial capitalization method C # string similarity comparison class
C # pattern Brush HatchBrush Usage instance C#ê1ó? Ado.net?áè? Excel±íμ?? ¨c# implements the method of sending a simple HTTP request WinForm get the current name instance rollup

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

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.