Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackOverflow Generic
//Title of this code //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 { public abstract class FooBase { public abstract void FooMethod(FooBase obj); } public class FooB { public void FooMethod(FooB ob) { } } //Implement FooBase so that Foo is guaranteed to have a FooMethod implementation public class Foo : FooB { public Foo() { } public Foo(Foo x, Foo y) { ThisX = x; ThisY = y; } public Foo ThisX { get; set; } public Foo ThisY { get; set; } //Override FooMethod so that it can do whatever Foo needs it to do /*public override void FooMethod(FooBase ob) { Console.WriteLine("Hiiiii\t" + ob); }*/ } public class Gen<T> where T : FooB { T obj; public Gen() { } public Gen(T x, T y) { Console.WriteLine("Gen(T x,T y)\t" + x.GetType().Name.ToString() + " " + y.GetType().Name.ToString());//+" "+obj.GetType().Name.ToString()); } public void Display(T ob) { obj = ob; Console.WriteLine("Display " + ob.GetType().Name.ToString() + " " + obj.GetType().Name.ToString()); //Fire the objests implementation of FooBase.FooMethod(FooBase obj) obj.FooMethod(obj); } } public class Program { public static void Main(string[] args) { Gen<Foo> m = new Gen<Foo>(); Foo ob1 = new Foo(); Foo ob2 = new Foo(); Console.WriteLine("Main " + m.GetType()); Console.WriteLine("Main " + ob1.GetType()); Console.WriteLine(); Gen<Foo> n = new Gen<Foo>(ob1, ob2); Console.WriteLine(); m.Display(ob1); //To stop the console Console.ReadLine(); } } }
run
|
edit
|
history
|
help
0
1.2 Basics: object orientation
Main
Root
ray's 2nd test
NumsToVars
Coding
MockTest
1
Detaylar
exception implicit toString