Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Generic Coveriant
//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(); } class MyClass<T> : IMyCoVarGenIF<T> { T obj; public MyClass(T v) { obj = v; } public T GetObject() { 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) { } // ... } public class Program { public static void Main(string[] args) { IMyCoVarGenIF<Alpha> AlphaRef = new MyClass<Alpha>(new Alpha("Alpha #1")); Console.WriteLine(AlphaRef.GetObject().GetName()); AlphaRef = new MyClass<Beta>(new Beta("Beta #1")); Console.WriteLine(AlphaRef.GetObject().GetName()); IMyCoVarGenIF<Alpha> AlphaRef2 =new MyClass<Beta>(new Beta("Alpha #1")); Console.WriteLine(AlphaRef2.GetObject().GetName()); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
4 Distinct Integer Custom Code Generator
Charan GR
Conversioni double
yari
edmond@DESKTOP-M2BC2LH
pattern2
Abstract Class
My wall
Calculadora
1
Please log in to post a comment.