The rules for method resolution can be complex and may not be fully understood by all developers. The situation becomes even more challenging when
dealing with method overloads that have optional parameter values.
This rule raises an issue when an overload with default parameter values is hidden by another overload that does not have the optional
parameters.
What is the potential impact?
See the following example:
MyClass.Print(1); // which overload of Print will be called?
public static class MyClass
{
public static void Print(int number) { }
public static void Print(int number, string delimiter = "\n") { } // Noncompliant, default parameter value is hidden by overload
}
In this code snippet, the Print
method is overloaded with two versions, where the first one hides the second one. This can lead to
confusion and uncertainty about which overload of the method will be invoked when calling it.