c# - How Can I use generic classes in another method when I dont know what is T? -


suppose have these classes:

public class nodeoutput<t> : nodedata {     public t value;     public nodeoutput(string name, t value)         : base(name)     {         this.value = value;     } } public class nodeinput<t> : nodedata {     public t value;     public nodeinput(string name, t value)         : base(name)     {         this.value = value;     }  } 

how can use these classes in method when dont know t yet? can not compiled:

public createconnection(nodeoutput<t> output, nodeinput<t> input) {  } 

but 1 seats easy compiler: though i'm not sure mean @ all!

public connection(nodeoutput<type> output, nodeinput<type> input) {  } 

here in function t not important me. need save output , input in 2 variables.

you can declare other method generic, too:

public void createconnection<t>(nodeoutput<t> output, nodeinput<t> input) {  } 

i added return type void (thanks dmitry bychenko pointing out). can change whatever need.

also, note: c#, not java. naming convention upper camel case.


Comments