Re: [2.0] Access Modifier
Actually, I have just modified the design of my code so this isn't really needed, but it would still be nice to know.
Re: [2.0] Access Modifier
There's no way to do that. All you can do is override/shadow the base implementation and either throw an exception or just leave the body empty.
It should be noted, though, that overriding follows the object while shadowing follows the type. That means that if you override a member in a derived class then cast an instance as the base type, it will still be the derived implementation of the member that gets invoked. If you shadow a member, on the other hand, casting as the base type gives access to the base implementation of the member shadowed in the derived type. Try this to see what I mean:
CSharp Code:
public class BaseClass
{
public virtual void Method1()
{
MessageBox.Show("BaseClass", "Method1");
}
public void Method2()
{
MessageBox.Show("BaseClass", "Method2");
}
}
public class DerivedClass : BaseClass
{
public override void Method1()
{
MessageBox.Show("DerivedClass", "Method1");
}
public new void Method2()
{
MessageBox.Show("DerivedClass", "Method2");
}
}
CSharp Code:
BaseClass b1 = new BaseClass();
b1.Method1();
b1.Method2();
DerivedClass d = new DerivedClass();
d.Method1();
d.Method2();
BaseClass b2 = (BaseClass)d;
b2.Method1();
b2.Method2();