There is any way to set the generic type (T) of class in the constructor only, but not in the declaration?
public class Gen<T>
{
}
public class Da
{
}
public class Program
{
public static Gen<?> gen;
public static void Main(string[] args)
{
gen = new Gen<Da>();
}
}
If I understand your requirements correctly, the easiest way to achieve this is to have a non-generic interface:
interface IGen { }
Then your generic class can be:
class Gen<T> : IGen { }
And the usage is:
IGen objectGen = new Gen<object>();
IGen intGent = new Gen<int>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With