Implementing a interface with template function with a template class C# -


i want implement interface template function. implemented class template class. want make sure template parameter of implemented function same of class

public interface {     t setvalue<t>(t v); }  public class b<valtype> : {     valtype val;      public t setvalue<t>(t v)     {         val = v;     } } 

the value of "val" should need set if t == valtype, there way in compile time.

one option: promote type interface:

interface a<t> {     t setvalue(t v); } 

then implement interface providing type:

class b<valtype> : a<valtype> {     public valtype setvalue(valtype v)      {          return v;     } } 

do note, point forwards interface used it's closed generic type:

a<int> ia = getb(); // whatever. 

Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -