Here is what I am trying to do:
if (a==true)
{
dbA objectInstance = new dbA();
}
else
{
dbB objectInstance = new dbB();
}
objectInstance.Name = "New name";
I get “the name objectInstance does not exist in the current context”, I assume because the def happens inside the conditional.
There must be a better pattern to do this – should I have dbA and dbB inherit from the same class?
Yes,
dbAanddbBwould need a common base class or interface and that base class or interface would need to have theNameproperty as part of its public contract.Then you could do this:
That being said I think an interface is your best choice here unless these types already share a base class.