In C++ templates, one can specify that a certain type parameter is a default. I.e. unless explicitly specified, it will use type T.
Can this be done or approximated in C#?
I'm looking for something like:
public class MyTemplate<T1, T2=string> {}
So that an instance of the type that doesn't explicitly specify T2
:
MyTemplate<int> t = new MyTemplate<int>();
Would be essentially:
MyTemplate<int, string> t = new MyTemplate<int, string>();
Ultimately I am looking at a case wherein there is a template that is fairly widely used, but I am considering expanding with an additional type parameter. I could subclass, I guess, but I was curious if there were other options in this vein.