Is operator overload...
Is operator overload...
Yes, operator overloading is supported in C#. C# allows you to overload most operators for your custom types, which provides a more natural and intuitive syntax when working with those types[1].
To overload an operator in C#, you define a special method with the operator
keyword. The method must be public
and static
, and at least one of its parameters must be of the type that contains the operator declaration[1].
C# supports overloading the following operators[1][2]:
+
, -
, !
, ~
, ++
, --
, true
, false
+
, -
, *
, /
, %
, &
, |
, ^
, <<
, >>
==
, !=
, <
, >
, <=
, >=
However, there are some operators that cannot be overloaded in C#, such as &&
, ||
, ?:
, is
, as
, and new
[1].
When overloading an operator, you must overload both the ==
and !=
operators, or both the <
and >
operators, or both the <=
and >=
...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào