Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Generic Reference constraint
/* while using Reference type constraints we create objects of type class, but when we pass the same object to the generic class we cannot access the methods of the cass. off course we can have base class constraints i just have doubt on thid*/ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class FooBase { } public class Foo:FooBase { public Foo() { } public Foo(Foo x,Foo y) { ThisX=x; ThisY=y; } public Foo ThisX{get;set;} public Foo ThisY{get;set;} public void FooMethod(Foo ob) { Console.WriteLine("Hiiiii\t"+ob); } } public class Gen<T> where T:FooBase { 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()); 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); } } }
run
|
edit
|
history
|
help
0
Bellman Ford algorithm helps to find the shortest path
1
1234
Example of dates in c#, Ejemplo de fechas en c#
MightConst - Runtime Constwrapper Value (C#)
code exple
araray
8
Understanding For loop and Return functions
ARM