parameter order independent function call

I would recommend just picking the order of arguments that makes sense to you, and sticking with that. Having multiple overloads of the exact same argument list in different orders is non-conventional and potentially confusing to consumers of your API.

One thing that can be done when calling methods is using Named Arguments. If your consumers use named arguments, they can put them in whatever order they want.

For example:

public static DateTime Add(int daysToAdd, DateTime date)
{
    return date.AddDays(daysToAdd);
}

private static void Main()
{
    // Call the method passing the int first, then the DateTime
    var newDate1 = Add(daysToAdd: 5, date: DateTime.Now);

    // Call the method passing the DateTime first, then the int 
    var newDate2 = Add(date: DateTime.Now, daysToAdd: 5);
}

Leave a Comment