I tried using method (foo2) from the template method (foo1) and compiler said that he doesn’t know this method (foo2) which belongs to that class (T).
What is the right syntax, which compiler accept it?
private void foo1<T>(T instance)
{
instance.foo2();
}
You should create constraint on generic type like in the code snippet below:
Which defines, that closed generic types can only be derived from
IFoointerface. But why don’t you stick with non-generic version like given below?