I have a method with two optional parameters. I want to shorten my code.
here is my code:
DataTable dtList;
if (!duration.ContainsKey("startDay") && duration.ContainsKey("endDay"))
{
dtList = GetAllReservation();
}
else if (duration.ContainsKey("startDay") && !duration.ContainsKey("endDay"))
{
dtList = GetAllReservation(duration["startDay"]);
}
else
{
dtList = GetAllReservation(duration["startDay"], duration["endDay"]);
}
is there any way to shorten this code to something like this:
dtList = GetAllReservation(duration["startDay"], duration?["endDay"]);
this is my method GetAllReservation:
public static DataTable GetAllReservation(string start = "1397/01/01", string end = "1400/12/29") =>
DataAccess.Select($"Exec ReservationList '{start}', '{end}'", ref _methodState);
ContainsKeycheck, and therefore will throw if key is not found.GetAllReservationmethod?Data Table?