C#

C#

Made by DeepSource

Methods should pass optional parameters to the base implementation CS-W1071

Bug risk
Critical

C# allows you to define methods with optional parameters. Optional parameters are those parameters where a default value is defined in case the user does not pass the required value. However, methods that are overriding base implementation should take care that its optional parameters are passed to the base implementation. This is in case the user provides a value that is different from the optional parameter's default value.

Bad Practice

public override void Method(char c, int x = 1)
{
    // ...
    // Does not pass `x`! If user passes some other value than `1`, it is never passed on to
    // the base implementation and the base implementation defaults to `x = 1`.
    base.Method(c);
}

Recommended

public override void Method(char c, int x = 1)
{
    // ...
    base.Method(c, x); // `x` is passed to the `base`
}