Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Operator overloading

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Specific explanation

You can redefine or overload the operators built into C #. Therefore, programmers can also use operators of user-defined types. An overloaded operator is a function with a special name, defined by the symbol of the operator followed by the keyword operator. Like other functions, overloaded operators have return types and parameter lists. Note that it must be decorated with public and must be a static method of the class. But not all built-in operators can be overloaded.

two。 Operators that can be overloaded and cannot be overloaded

The unary operators of +, -,!, ~, +,-- true false can be overloaded. True false must be overloaded in pairs

+, -, *, /,% these binary operators can be overloaded.

These comparison operators can be overloaded. Must be overloaded

&, | | these conditional logical operators cannot be directly overloaded.

+ =,-=, * =, / =,% = these assignment operators cannot be overloaded.

=,.,?:,->, new, is, sizeof, typeof operators cannot be overloaded.

3. Grammar

The operator keyword is used to declare operators in a class or structure declaration. There are two main forms:

"1" public static result-type operator unary-operator (op-type operand)

"2" public static result-type operator binary-operator (op-type operand, op-type2 operand2)

Note:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report