Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
generics one more doubt-stack overflow exception
//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 class GenBase<T,V> { public T tbase; public V vbase; GenBase<T,V> g=new GenBase<T,V>();//Error line public GenBase() { } public GenBase(T t,V v) { tbase=t; vbase=v; } public GenBase(V v,T t) { tbase=t; vbase=v; } public GenBase(T t) { tbase=t; } public GenBase(V v) { vbase=v; } public void BDisplay() { Console.WriteLine("Base_t: "+tbase); Console.WriteLine("Base_v: "+vbase); } } public class GenDerive<T,V>:GenBase<T,V> { T tderiv; GenBase<T,V> g=new GenBase<T,V>(); GenDerive<T,V> d=new GenDerive<T,V>();//Error line public GenDerive() { } public GenDerive(T t) { tderiv=t; } public GenDerive(T t,V v):base(v) { tderiv=t; } public void DDisplay() { Console.WriteLine("Deriv_t: "+tderiv); Console.WriteLine("Base_v: "+vbase); } } public class Gen3<T,V>:GenDerive<T,V> { GenDerive<T,V> d=new GenDerive<T,V>(); GenBase<T,V> bd=new GenDerive<T,V>(); } public class Program { public static void Main(string[] args) { GenBase<int,string> gb=new GenBase<int,string>(10,"Hello"); GenBase<string,int> gb2=new GenBase<string,int>("Hello",10); GenDerive<string,int> gd=new GenDerive<string,int>("Hii",10); GenDerive<int,string> gd2=new GenDerive<int,string>(10,"Hii"); gb.BDisplay(); Console.WriteLine(); gb2.BDisplay(); Console.WriteLine(); gd.DDisplay(); Console.WriteLine(); gd.BDisplay(); Console.WriteLine(); gd2.DDisplay(); Console.WriteLine(); gd2.BDisplay(); } } }
run
|
edit
|
history
|
help
0
HTML Hex to RGB without using System.Drawing C#
mine
Testing 10
Basic
T F
Remove dublicates
Sort A List of Ages of Students (Solution: Stack / O(N^3) Complexity)
fg erter r
my
Explicit Interface Examplle