c# – Which is better, two methods or one with a default parameter?


The self-written library has a method that can take either one parameter or two, if one, then we have a default for the second. The question is how best to do it, create two overloaded methods in the interface, or create one with a second default parameter?

// 1.

interface IExample {
    void Method(int a);
    void Method(int a, int b);

// 2.

interface IExample {
    void Method(int a, int b = DEFAULT);


If you yourself say that the default value will be assigned to the second parameter if it is not specified, then writing two methods is simply meaningless. This wastes memory storing two different methods with essentially identical functionality.

The second option is definitely better. Overloaded methods are created in cases when the second (n-th in the general case) parameter is not needed and it does not participate in any way in the calculations performed by the method.

Scroll to Top