Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Overloading == operator (for comparing values inside objects)
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { class Number { int n; public Number() { n=0; } public Number(int x) { n = x; } // operator == overloaded, because it will not compare automatically on operands of object // if this overloading is not written, if(n1==n2) will always return false even if the values are same public static bool operator == (Number x, Number y) { if(x.n == y.n) return true; else return false; } public static bool operator != (Number x, Number y) { if(x.n != y.n) return true; else return false; } public int getValue() { return n; } } public class Program { public static void Main(string[] args) { Number n1=new Number(5); Number n2=new Number(15); if(n1==n2) // == operator overloaded along with != (which is mandatory) Console.WriteLine("Equal"); else Console.WriteLine("Not Equal"); } } }
run
|
edit
|
history
|
help
0
adcsasxsd
SVSVSV
Reflection 2
Fff
golestanali
The Collatz Conjecture
filter distinct items from the array without builtin function - Seeni
towers of hanoi
Battle System Algorythm
time