Câu hỏi phỏng vấn C#
Câu hỏi

Is operator overload...

Câu trả lời

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]:

  • Unary operators: +, -, !, ~, ++, --, true, false
  • Binary arithmetic operators: +, -, *, /, %, &, |, ^, <<, >>
  • Equality operators: ==, !=, <, >, <=, >=

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

senior

Gợi ý câu hỏi phỏng vấn

junior

What is an Abstract Class?

middle

Why can't you specify the accessibility modifier for methods inside the Interface?

junior

What are partial classes?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào