MSDN: (while the quote and link are to VB documentation, the content applies equally to C#)
Determining Whether an Optional Argument Is Present
A procedure cannot detect at run time whether a given argument has been omitted or the calling code has explicitly supplied the default value. If you need to make this distinction, you can set an unlikely value as the default. The following procedure defines the optional parameter office, and tests for its default value, QJZ, to see if it has been omitted in the call:
[
^]
What you can do is to make your optional parameters nullable:
public static void SomeStaticMethod(int? intParam1 = null, bool? boolParam1 = null, string stringParam1 = null)
{
int defaultInt = -1;
bool defaultBool = false;
string defaultString = "Default";
if (intParam1 == null)
{
} else if (intParam1 == defaultInt)
{
}
if (boolParam1 == null)
{
} else if (boolParam1 == defaultBool)
{
}
if (stringParam1 == null)
{
} else if (stringParam1 == defaultString)
{
}
}
You'll note that Type 'String (a strange "flavor" of a RefernceType[1]) is Nullable; for the ValueTypes you use, you add the '?' to the Type Name as shown here.
I consider it a reasonable expectation that users of code be aware of the requirements for parameters (calling conventions).
Another strategy is method-overloading where you define a series of methods with the same names and return Types, but with different (required, not optional) parameters. Then, you can be absolutely sure which method overload was called. But, consider the case you had three parameters and you wanted to write a separate method overload for every possible case: none : a b c : ab ac bc : abc ... a lot of work !
[1] Look at Eric Lippert's blog entries, and comments on StackOverflow about the complexity of how Type 'String is managed in .NET