Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Test equality...1
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public interface ISeries<T>:IEquatable<T> { T GetNext(); // return next element in series void Reset(); // restart the series void SetStart(T v); // set the starting element } // Implement ISeries. class ByTwos<T> : ISeries<T> { T start; T val; // This delegate defines the form of a method // that will be called when the next element in // the series is needed. public delegate T IncByTwo(T v); // This delegate reference will be assigned the // method passed to the ByTwos constructor. IncByTwo incr; public ByTwos(){} public ByTwos(IncByTwo incrMeth) { start = default(T); val = default(T); Console.WriteLine("ByTwos "+incrMeth.GetType().Name.ToString()); incr = incrMeth; Console.WriteLine("ByTwos "+incr.GetType().Name.ToString()); } public bool Equals(T tp) { if(this.Equals(tp)) return true; else return false; } public T GetNext() { //Console.WriteLine(val.GetType().Name.ToString()); val = incr(val); Console.WriteLine("GetNext "+val.GetType().Name.ToString()+" "+ incr.GetType().ToString()); return val; } public void Reset() { val = start; } public void SetStart(T v) { val=v; /*start = v; val = start;*/ } } public class ByOne<T,V>:IEquatable<T> { public T t; public V v; public ByOne(T a,V b) { t=default(T); v=default(V); } public bool Equals(T tp) { if(this.Equals(tp)) return true; else return false; } public bool Equals(T tp,V vp) { if(tp.Equals(vp)) return true; else return false; } public bool Equals(V vp) { if(this.Equals(vp)) return true; else return false; } } class ThreeD { public int x, y, z; public ThreeD(int a, int b, int c) { x = a; y = b; z = c; } } public class Program { // Define plus two for int. static int IntPlusTwo(int v) { return v + 2; } // Define plus two for double. static double DoublePlusTwo(double v) { return v + 2.0; } // Define plus two for ThreeD. static ThreeD ThreeDPlusTwo(ThreeD v) { if(v==null) return new ThreeD(01, 01, 01); else return new ThreeD(v.x + 2, v.y + 2, v.z + 2); } public static void Main(string[] args) {// Demonstrate int series. ByTwos<int> intBT = new ByTwos<int>(IntPlusTwo); Console.WriteLine("Main "+intBT.GetType().Name.ToString()); for(int i=0; i < 5; i++) Console.Write(intBT.GetNext() + " "); Console.WriteLine(); // Demonstrate double series. ByTwos<double> dblBT = new ByTwos<double>(DoublePlusTwo); dblBT.SetStart(11.4); for(int i=0; i < 5; i++) Console.Write(dblBT.GetNext() + " "); Console.WriteLine(); // Demonstrate ThreeD series. ByTwos<ThreeD> ThrDBT = new ByTwos<ThreeD>(ThreeDPlusTwo); Console.WriteLine("Main "+ThrDBT.GetType().Name.ToString()); ThreeD coord; for(int i=0; i < 5; i++) { coord = ThrDBT.GetNext(); Console.Write(coord.x + "," + coord.y + "," + coord.z + " "); } Console.WriteLine("ByOne\n\n"); Console.WriteLine(intBT.Equals(dblBT)); int me1=10; double me2=15.2; byte me3=10; float me4=6.1F; ByOne<int,double> bone=new ByOne<int,double>(me1,me2); ByOne<int,double> bone1=new ByOne<int,double>(me3,me2); ByOne<int,double> bone2=new ByOne<int,double>(me3,me4); Console.WriteLine(me3.Equals(bone1,bone2)); } } }
run
|
edit
|
history
|
help
0
Seizoen bepalen in C#
HMS abstract
Programmes
Liczba powtórzająca
C# Calculator Simple
up casting down casting
iran
Retirar valores das tags de um XML padrão TISS/ANS SIB
c++
Can a == true && a == false be true in C#?