0

I have a 2D vector class and I have a function that multiplies vectors, one the adds, divides, ect. I was wondering if instead of calling a function, if it would be possible to control what happens when I use *,/,+, or - . For example, could I have:

vector1 * vector2

do the same thing as

multiplyVectors(Vector1, Vector2)
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 3
    Search keywords: "C# operator overloading". First link on http://www.bing.com/search?q=C%23+operator+overloading should be good start. – Alexei Levenkov Jun 14 '13 at 05:07
  • I can't say that I'm familiar with c# vector operations, but I am intimately familiar vector mathematics. There are many different forms of vector multiplication, and you have to know which form you need. In this case, you may not get what you want. – Mlagma Jun 14 '13 at 05:09

1 Answers1

4
public class Vector2D
{
    // ...

    public static Vector2D operator * (Vector2D v1, Vector2D v2)
    {
        return multiplyVectors(v1, v2);
    }
}
paddy
  • 60,864
  • 6
  • 61
  • 103