My understanding is that it is possible to Override a method (marked as Virtual) in a base class from a derived class using the keywords override.
But what about overriding a method in the same class?
In my specific case, I have a class x with 2 methods. Method a has some common behavior with b, and b adds functionality to method a.
In the past, I have duplicated the code of a in b and added the new functionality into b.
I would like to know if there is a better approach so I can centralize the behavior of method a.
public class x
{
public static void a() {}
public static void b() {}
}
You could simply call your method
a()from within your methodb(). No need (and no way) to override a method.On the other hand you could have parameter overloads for your method.
In this case you can call
a(1)ora()with the same result.