Reputation: 387
I have a class with public MyClass(Form form)
as constructor
Is it possible for me to use the functions I made in a class derived from Form
in this class? (Named DerivedClass
)
For now I was thinking, check if form
is DerivedClass
then use its functions, but it doesn't seem to work.
if (form is DerivedClass)
{
form.DerivedClassFunction();
}
Doing this I get the same error :
"Form" does not contain a definition of "DerivedClassFunction"
Upvotes: 1
Views: 432
Reputation: 8743
You have to convert it to your derived type, either via:
if (form is Derived)
{
((Derived)form).DerivedClassFunction();
}
or (new in C# 7):
if (form is Derived derived)
{
derived.DerivedClassFunction();
}
Upvotes: 6