Answers

Question and Answer:

  Home  Unity Developer

⟩ Tell us what is Operator Overloading and how does it work?

Most of the built-in operators available in C# can be overloaded or redefined using the operator keyword. The sample code below depicts the syntax used to implement the addition operator (+) for a user-defined class.

public static Rectangle operator+ (Rectangle b, Rectangle c)

{

Rectangle rectangle = new Rectangle();

rectangle.length = b.length + c.length;

rectangle.breadth = b.breadth + c.breadth;

rectangle.height = b.height + c.height;

return rectangle;

}

 231 views

More Questions for you: