I want something like this:
class Foo<T>{...}
class Boo<T>{
Queue<T> stuff = new Queue<T>();
public void Boo(Foo<T>){...};
}
...
//Extract the generic type - string - to define the type
//of MyBoo.
var MyBoo = new Boo(new Foo<string>());
I get the error “generic type ‘Boo’ requires ‘1’ type arguments. Ya, I fixed the problem by stating the template type explicitly, but I’d like to know if there was/is a way to extract that type implicitly, rather than having to state it explicitly.
This other post may be related, but I’m not sure.
You can’t do it implicitly directly with the constructor of a generic type, but you could from a generic method, e.g. in a non-generic class:
Then:
Of course, it doesn’t have to be another class called
Boo– it could be something completely different, and it could be an instance method of something else:The important point is that it’s a generic method – type arguments can be inferred for generic methods, but not for generic types.