Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Importent Gen_Coverent Example-1
//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 interface IMyCoVarGenIF<out T> { T GetObject(); T GetObject2(); // T GetObject2( out T x); // void M<V>() where V:T; // Error, covariant T cannot be used as constraint } class MyClass<T> : IMyCoVarGenIF<T> { T obj; public MyClass(){} public MyClass(T v ) { obj = v; } public T GetObject() { return obj; } public T GetObject2() { return obj; } } class MyClass2<T> : MyClass<T> { T obj; public MyClass2(T v ) { obj = v; } public T GetObject() { return obj; } public T GetObject2() { return obj; } } class Alpha { string name; public Alpha(string n) { name = n; } public string GetName() { return name; } // ... } class Beta : Alpha { public Beta(string n) : base(n) { } // ... } class Gama : Beta { public Gama(string n) : base(n) { } // ... } public class Program { public static void Main(string[] args) { Alpha ap =new Alpha("Alpha #1"); Beta bt=new Beta("Beta #1"); Beta bt2=new Beta("Beta #2"); Gama gm=new Gama("Gama #1"); string x="10"; MyClass<Alpha> ap2=new MyClass<Alpha>(bt); MyClass2<Alpha> ap_2=new MyClass2<Alpha>(ap); MyClass2<Alpha> ap_3=new MyClass2<Alpha>(bt); MyClass2<Alpha> ap_4=new MyClass2<Alpha>(gm); // MyClass2<Beta> bt_2=new MyClass2<Beta>(ap); MyClass2<Beta> bt_3=new MyClass2<Beta>(bt); MyClass2<Beta> bt_4=new MyClass2<Beta>(gm); // MyClass2<Gama> gm_2=new MyClass2<Gama>(ap); // MyClass2<Gama> gm_3=new MyClass2<Gama>(bt); MyClass2<Gama> gm_4=new MyClass2<Gama>(gm); MyClass<Gama> gm_5=new MyClass2<Gama>(gm); // MyClass2<Alpha> ab_2=new MyClass2<Beta>(ap); // MyClass2<Alpha> ab_3=new MyClass2<Beta>(bt); // MyClass2<Alpha> abm_2=new MyClass2<Beta>(gm); // MyClass2<Alpha> am_3=new MyClass2<Gama>(bt); // MyClass2<Alpha> am_4=new MyClass2<Gama>(gm); // MyClass2<Alpha> am_5=new MyClass2<Gama>(ap); //MyClass2<Beta> gm_6=new MyClass2<Gama>(gm); //MyClass2<Beta> gm_7=new MyClass2<Gama>(bt); // MyClass2<Alpha> ab_2=new MyClass2<Beta>(ap); //MyClass<Beta> ab_3=new MyClass2<Beta>(ap); // MyClass<Alpha> abm_2=new MyClass2<Beta>(gm); // MyClass2<Alpha> am_3=new MyClass2<Gama>(bt); // MyClass2<Alpha> am_4=new MyClass2<Gama>(gm); // MyClass2<Alpha> am_5=new MyClass2<Gama>(ap); //MyClass2<Beta> gm_6=new MyClass2<Gama>(gm); //MyClass2<Beta> gm_7=new MyClass2<Gama>(bt); IMyCoVarGenIF<Alpha>apg= new MyClass<Gama>(gm); IMyCoVarGenIF<Alpha>apg0= new MyClass<Alpha>(gm); IMyCoVarGenIF<Alpha>apg1= new MyClass2<Alpha>(ap); IMyCoVarGenIF<Alpha>apg2= new MyClass2<Alpha>(bt); IMyCoVarGenIF<Alpha>apg3= new MyClass2<Alpha>(gm); //IMyCoVarGenIF<Alpha>apg4= new MyClass2<Gama>(ap); // IMyCoVarGenIF<Alpha>apg5= new MyClass2<Gama>(bt); IMyCoVarGenIF<Alpha>apg6= new MyClass2<Gama>(gm); IMyCoVarGenIF<Alpha>apg7= new MyClass2<Beta>(bt); // IMyCoVarGenIF<Alpha>apg8= new MyClass2<Beta>(ap); IMyCoVarGenIF<Alpha>apg9= new MyClass2<Beta>(gm); // IMyCoVarGenIF<Beta>apg10= new MyClass2<Gama>(bt); // IMyCoVarGenIF<Beta>apg11= new MyClass2<Gama>(ap); IMyCoVarGenIF<Beta> apg12= new MyClass2<Gama>( ); // IMyCoVarGenIF<Gama>apg13= new MyClass2<Gama>(bt); // IMyCoVarGenIF<Gama>apg14= new MyClass2<Gama>(ap); IMyCoVarGenIF<Gama>apg15= new MyClass2<Gama>(gm); IMyCoVarGenIF<Beta>apg16= new MyClass2<Beta>(bt); // IMyCoVarGenIF<Beta>apg17= new MyClass2<Beta>(ap); IMyCoVarGenIF<Beta>apg18= new MyClass2<Beta>(gm); MyClass<Alpha> ap3=new MyClass<Alpha>(ap); // MyClass<Beta> ap4=new MyClass<Beta>(ap); MyClass<Beta> ap5=new MyClass<Beta>(bt); // MyClass<Beta> ap8=new MyClass<Beta>(ap2); // MyClass<Beta> ap6=new MyClass<Alpha>(ap); // MyClass<Beta> ap7=new MyClass<Alpha>(bt); Console.WriteLine(ap2.GetObject2()+"/ "+ap3.GetObject2()+"/ "+ap5.GetObject2()/*+" "+ap8.GetObject2()*/); IMyCoVarGenIF<Alpha> AlphaRef = new MyClass<Alpha>(ap); Console.WriteLine(AlphaRef.GetObject().GetName()); //Console.WriteLine(AlphaRef.GetObject2().GetName()); IMyCoVarGenIF<Beta>BetaRef2 =new MyClass<Beta>(bt); Console.WriteLine(BetaRef2.GetObject().GetName()); AlphaRef = new MyClass<Beta>(bt2); Console.WriteLine(AlphaRef.GetObject().GetName()); } } }
run
|
edit
|
history
|
help
0
Sum Matrix Main Diagonal
Generics Base class constraints
GYT
buble sort
Rijndael AES key generator C#
12
C# - String Parsing
Project Euler problem 1
7. Asynchrony
Interlocked Class (atomic operations)