I have the following class
public class MyClass
{
public int ElementId {get; set;}
public int? LowerBoundary {get; set;}
public int? UpperBoundary {get; set;}
public int SpecificMethod() {}
public void CommonMethod()
{
int expectedValue = SpecificMethod();
}
}
CommonMethod() is the same for every instance of this class, but I'd like SpecificMethod() to be different for each one. This method should always return an int, but it could take 0, 1 or 2 parameters (which are its own values for LowerBoundary and UpperBoundary properties).
Is there a way to achieve this? Since the number of parameter is variable, I understand I can't make SpecificMethod to be a Func property.
Perhaps you can use
paramskeywords:https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/params
You can also define three overloaded methods:
You can create as many as overloaded methods with any types you need.
https://learn.microsoft.com/dotnet/standard/design-guidelines/member-overloading
Perhaps you may set the method as private or protected if only used by the instance.