2

i have a base class lets call it as BaseDatabaseOperationClass

public abstract class BaseDatabaseOperationClass
{
   public virtual void Insert(int id,int name)
   {
        //make insertion bla bla
   }
}

and there are many child classes. But in one of them i have extra method and the story starts here.

 public class ChildClass : BaseDatabaseOperationClass
 {
     public void DifferentInsert(int id,int name)
     {
           //make some controls add some extra things bla bla
           //changes id and name
           base.Insert(id,name);

     }
 }

but now i do not want that any instance of ChildClass can use the Insert method. Basically i want to change the access modifier of the Insert method of BaseDatabaseOperationClass by overriding it in ChildClass. But i know it is not allowed. So what should i do?

brtb
  • 2,201
  • 6
  • 34
  • 53
  • Hide the base method using the [new](http://msdn.microsoft.com/en-us/library/435f1dw2.aspx) modifier. You still will be able to call the method if you reference the instance of ChildClass through its base type. – galenus Nov 05 '14 at 12:36
  • You can use an [intermediate base class](https://stackoverflow.com/a/29173561/429091) to both `override` the base class’s `virtual` method and provide a `new public` method with the same name and parameters. – binki Dec 28 '17 at 15:47

0 Answers0