Operators that can be reloaded in C #

Source: Internet
Author: User
In C #, the operator overload must be declared as public and static, and the overload = and! =, It is best to reload the equals () and gethashcode () methods, because the = and equals () methods should maintain the same logic (not reload the last two methods, will generate a compiler warning)

ClassOther

Operation Computing Character

LimitedSystem

Arithmetic binary Operators

+ ,*,/,-, %

None

Arithmetic unary operator

+,-, ++,--

None

Bitwise binary operator

&, |, ^, <,>

None

Bitwise unary Operators

!, ~, True, false

TrueAndFalseThe operators must be reloaded in pairs.

Comparison Operators

= ,! =, >=, <, <=,>

Must be reloaded in pairs

Value assignment operator

+ =,-=, * =,/=, >>=, <=, % =

, & =, | =, ^ =

You cannot explicitly reload these operators.+,-, %They are implicitly overwritten.

Index Operators

[]

You cannot directly reload the index operator. The2The member types of the indexer introduced in chapter allow the support of index operators in the class and Structure

Data type conversion Operator

()

You cannot directly overload the data type conversion operator. User-Defined data type conversion(In this chapter2Introduction)Allow custom data type conversion

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.