I have one class with 2 properties called MinValue, MaxValue , If somebody wants to invoke this class and Instantiate this class ,I need some to have constructor that allow select MinValue Or Max Value Or Both Of them , the MinValue and MaxValue both of them are int,
So the constructor doesn’t allow me like this:
public class Constructor
{
public int Min { get; set; }
public int Max { get; set; }
public Constructor(int MinValue, int MaxValue)
{
this.Min = MinValue;
this.Max = MaxValue;
}
public Constructor(int MaxValue)
{
this.Max = MaxValue;
}
public Constructor(int MinValue)
{
this.Min = MinValue;
}
}
Now I cannot do that because I cannot overload two constructor,
How Can I implement this?
I would create two static methods for the two parts where you’ve got only partial information. For example:
(The C# 4 option of using named arguments is good too, but only if you know that all your callers will support named arguments.)