C # - How to skip options with default values?

Consider the following example method:

public void MyMethod (string par1, bool par2 = "true", string par3="")
{
}

Now let's say that I call MyMethod and set the par3 value to "IamString".

How can I do this without setting par2 to true or false?

Basically I want to leave par2 as default.

I ask this because in Flash ActionScript this can be done using the default keyword so that I can call MyMethod ("somestring", default, "IamString") and par2 will be interpreted as true, which is its default value. I wonder if this is also possible in C #.

+5
source share
2 answers
public void MyMethod (string par1, bool par2 = "true", string par3=""){}
Myclass.MyMethod(par1:"par1", par3:"par3");

By the way, this will not work: bool par2 = "true"

string par2 = "true"

or

bool par2 = true

, , :

default(T)

+11

:

instance.MyMethod( "Hello", par3:"bla" );

.

:

bool par2 = true

.

+9