O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

22.3. Another example of operator overloading

Just for developers who enjoy dabbling with matrices, here's another full example. [4]

[4] You can skip this if you have understood the previous example. You need to understand matrix mathematics to appreciate what is going on here. (Time to search for that old high school math textbook!)

 1: using System; 2: 3: // class represents a 2 " 2 matrix 4: class Matrix{ 5: 6: // these 4 fields represent the 4 values in the 2 " 2 matrix 7: public float TopLeft; 8: public float TopRight; 9: public float BottomLeft; 10: public float BottomRight; 11: 12: // constructor 13: public Matrix 14: (float TopLeft, float TopRight, float BottomLeft, float BottomRight){ 15: this.TopLeft = TopLeft; 16: this.TopRight = TopRight; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required