C# Override with different parameters?

后端 未结 5 1523
天命终不由人
天命终不由人 2020-12-11 16:29

Here is an example of what I am looking to do.

public class A
{
    public virtual void DoSomething(string a)
    {
      // perform something
    }
}
public         


        
5条回答
  •  青春惊慌失措
    2020-12-11 16:51

    Slight necro, but when you overload you can call the original method from the new one.

    so

    public class B : A {
    
        public virtual void DoSomething (string a, string b) {
            base.DoSomething(_a);
            //Do B things here
        }
    }
    

    This allows you to modify the method instead of completely redoing it :)

提交回复
热议问题