I want to define an object
and make instance of it to other class, but I can't call the method, here's my code:
class Test1
{
public bool True_1()
{return true;}
}
class Test2
{
public bool True_2()
{return true;}
}
class MainClass
{
static void Main()
{
object a;
bool flag = true; // or false
if (flag)
a = new Test1();
else
a = new Test2();
if (a is Test1)
a.True_1(); //error before compiling
else
a.True_2(); //error before compiling
}
}
}
I know there's a way of creat an interface I_Test
, and do this:
class Test1:I_Test
class Test2:I_Test
but since class Test2
is a dll from third-party so I can't add :I_Test
to it,
so I want to make my code here achievable, any suggestion? thx!