Stack Exchange
Used Named Optional Parameters for Method
I have a method where I have several optional boolean parameters,  different properties of an object will be given a value based on which parameters are true.
Here is the method for context:
public static AutoPatientLookup InitializeTestPatientInfo(bool SSN = false, bool PatientNumber = false, bool Gender = false)
{
    AutoPatientLookup TestAPIParameters = new AutoPatientLookup();
    TestAPIParameters.FirstName = "First";
    TestAPIParameters.LastName = "Last";
    TestAPIParameters.DOB = "4/9/1953";
    TestAPIParameters.PracticeID = 11071;

    if (SSN)
    {
        TestAPIParameters.SSN = 000010281;
    }
    if (PatientNumber)
    {
        TestAPIParameters.PatientNumber = 458;
    }
    if (Gender)
    {
        TestAPIParameters.Gender = "F";
    }

    return TestAPIParameters;
}

However, sometimes I want the second or third boolean parameter to be true but I'm unable to designate that as the parameter I want to switch without explicitly stating true or false for the preceding parameters.
This if I want to initialize an AutoPatientLookup object that has a value for its gender property, I would have to call it like this:
InitializeTestPatientInfo(false,false,true);

I tried something along the lines of 
InitializeTestPatientInfo(Gender = true);

and
InitializeTestPatientInfo(bool Gender = true);

but nothing seems to work. Is there a correct syntax for accomplishing for what I'm attempting? Even though the initialization syntax isn't very inconvenient when there are only three boolean parameters this could be more applicable if there are dozens.

Gender:true and so on By the way, Intellisense should show it for you

It's amazing what something like "c# calling optional parameters" can find -  https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments , https://www.dotnetperls.com/optional-parameters .. anyway, the different syntax is needed because C# method calls support X(expr), so X(Gender = true) is attempting to assign to Gender (which does not exist) and then pass the result of the assignment expression to the method call.. (this is also why x = y = z is allowed in C#).

Beware of optional parameters in public methods. Read the second part of my answer here to learn why.

@Steve Your suggestion worked but for some reason Intellisense isn't picking up on it.

Glad to help :-)

Another option is using enums - which are great for readability. Sometimes boolean variables don't explain the responsibility/intent of the variable well. For instance: Gender ( has gender filled out, is gender,  has particular gender etc... ) it's quite vague.

You can name your parameter that you are assigning:
Do this instead 
InitializeTestPatientInfo(Gender: true);


The syntax you want to use is:
InitializeTestPatientInfo(Gender: true);


Try
InitializeTestPatientInfo(Gender: true);

