I am sure that this was asked earlier, but, unfortunately, the only thing I found was this one , which was not a solution for me. In my current project, I am doing something like:
private object obj;
private void Initialize()
{
obj.Initialize();
}
private void CreateInstanceA()
{
obj = Activator.CreateInstance(typeof(MyClassA));
}
private void CreateInstanceB()
{
obj = Activator.CreateInstance(typeof(MyClassB));
}
This code does not work, of course, because I did not use it obj, because its type changes dynamically.
How can I use it dynamically?
source
share