C#C
C#3y ago
Shillelagh

❔ Create new instance of type unknown at runtime?

Say I have a base class, abstract class Letter with child classes A, B, and C.

If I have a variable: Letter myLetter which is of unknown type (can be any of A, B, or C, the only guarantee is it's a child of Letter), how can I create a new instance of whatever class myLetter is?

I need to create a new instance (must call default constructor as well) of whatever myLetter is and store it in another variable (say myLetter2)
Was this page helpful?