Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Operator Overloading Example (+, -, *, /, ==, !=)
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Triangle t01 = new Triangle(2,3,4); Triangle t02 = new Triangle(1.5f,2.5f,3.5f); Triangle t03 = t01 / t02; Console.WriteLine(t03.side01); if(t01 == t02) Console.WriteLine("MATCHING"); else Console.WriteLine("NOT MATCHING"); } } public class Triangle { public float side01; public float side02; public float side03; public Triangle(){} public Triangle(float _01, float _02, float _03) { side01 = _01; side02 = _02; side03 = _03; } public static Triangle operator+ (Triangle b, Triangle c) { Triangle tri = new Triangle(); tri.side01 = b.side01 + c.side01; tri.side02 = b.side02 + c.side02; tri.side03 = b.side03 + c.side03; return tri; } public static Triangle operator- (Triangle b, Triangle c) { Triangle tri = new Triangle(); tri.side01 = b.side01 - c.side01; tri.side02 = b.side02 - c.side02; tri.side03 = b.side03 - c.side03; return tri; } public static Triangle operator* (Triangle b, Triangle c) { Triangle tri = new Triangle(); tri.side01 = b.side01 * c.side01; tri.side02 = b.side02 * c.side02; tri.side03 = b.side03 * c.side03; return tri; } public static Triangle operator/ (Triangle b, Triangle c) { Triangle tri = new Triangle(); tri.side01 = b.side01 / c.side01; tri.side02 = b.side02 / c.side02; tri.side03 = b.side03 / c.side03; return tri; } public static bool operator== (Triangle b, Triangle c) { if(b.side01 == c.side01 && b.side02 == c.side02 && b.side03 == c.side03) { return true; } else { return false; } } public static bool operator!= (Triangle b, Triangle c) { if(b.side01 != c.side01 || b.side02 != c.side02 || b.side03 != c.side03) { return true; } else { return false; } } } }
run
|
edit
|
history
|
help
1
hamming distance
V 1.2
asxasxdf
Chest Interaction Unity
Convert string to TimeSpan in C#
Parse SQL Insert
png
C# Abstract Syntax Tree Example: Compiler for a numeric expression
One liner recursive prime generator
sktieritjre