Run Code
|
API
|
Code Wall
|
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
C++ lesson
Problem: binary
sdfrgthyjui65trfvf
Explanation about Aggregate method in C#
Generate Secure GUID
масиви форіч
simultQ
matrix function
Generic class and method example in C#
Lottofacil