Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific form of Constructor in C#

I'm studying ICT. One of my courses is C# and another is Physics. Our Physics teacher used Visual Studio to animate some movements gave us some of the code he used to do it. He told us to look it up. Here's something I don't recognize:

public static Vector operator + (Vector v1, Vector v2)
{
    return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
}

That is supposed to be a constructor, but I've never seen anything like it before. I don't know what it's called, so I don't know what to google for.

Can someone enlighten me please?

like image 573
Vordreller Avatar asked Nov 29 '22 07:11

Vordreller


1 Answers

That is called "operator overloading". It is not a constructor but returns a new Vector.

See: Operator Overloading

like image 129
Leonidas Avatar answered Dec 04 '22 13:12

Leonidas