dimanche 25 mars 2018

Creating generic type with reflection

I'm studying C# at my university and I have to create an generic class instance with reflection, but I don't know how to do it exactly. Here's my code:

public class MyClass <A, B>
{
    protected A a;
    protected B b;
    public MyClass(A a, B b) { this.a = a; this.b = b; }
}
 static void Main(string[] args)
    {
        Type typ = typeof(MyClass<int, int>);
        object obj = Activator.CreateInstance(typ);

    }

And my question is: how can I pass parameters to constructor using typeof?





Aucun commentaire:

Enregistrer un commentaire