If you want that your library class Parent method which name Method will not be callable from the outside you need to change access modifier. Your class hasn't access modifier, so, be default it is Internal - The type or member can be accessed by any code in the same assembly, but not from another assembly. The same accessibility is for method Method as it has access modifier public. If you want that implemented in class Method can be accessible only for derived class instance you need all access modifiers public for overloaded Method variations to change to protected and then in a child class hide this method overloaded methods. If you want these hidden methods to be used from outside you need to change their access modifiers from private to public. Example of this implementation:
namespace HideBaseClassMethod
{
class Program
{
static void Main(string[] args)
{
Parent myParent = new Parent();
//myParent. - no one of overloaded protected methods are accessible after dot operator
Child myChild = new Child();
myChild.Method(2.5, 4.3); //double
myChild.Method(2, 4);//int
Parent myChildCreatedAsParent = new Child();
//myChildCreatedAsParent. - no one of overloaded protected methods are accessible after dot operator
}
}
class Parent
{
protected double Method(double a, double b)
{
Console.WriteLine($"I am a parent double method {a} + {b}");
return a + b;
}
protected int Method(int a, int b)
{
Console.WriteLine($"I am a parent integer method {a} + {b}");
return a + b;
}
}
class Child:Parent
{
public new double Method(double a, double b)
{
Console.WriteLine($"I am a child double method {a} * {b}");
return a * b;
}
public new int Method(int a, int b)
{
Console.WriteLine($"I am a child integer method {a} * {b}");
return a + b;
}
}
}
The result of this program execution will be:
I am a child double method 2.5 * 4.3
I am a child integer method 2 * 4