I have 2 methods as following:
Method1(int a, int b)
{
var type = Typ1(a, b);
}
Method2
{
var type = Typ2(a, b);
}
I'd like to write a generic method which does the work:
GenericMethod<T>(int a, int b)
{
var type = new T(a, b);
}
But T doesn't accept any input parameter. How could I achieve this?
I know using Activator.Instance(T, a, b)
I can do that but it has a high performance cost.
I also know that I can call the default constructor of a generic type using T() then setting the properties,but in my case, I'd like to pass 2 parameters which are compulsory.
I don't want to introduce a constructor with no parameter.
Is there any way to do this with generics?
Thanks,