How to define a method with an optional parameter?

  • Thread starter Thread starter Fir5tSight
  • Start date Start date
F

Fir5tSight

Hi,

I have an existing method as follows:

public void InsertScan(int aDistributionCommonInstanceID)

Now I'll need to add a parameter, so it should look like the following:

public void InsertScan(int aDistributionCommonInstanceID, bool bCore)

I want to make this new parameter OPTIONAL as I don't want to change
any existing code. Could anyone advise me on how?

Thanks!

-Emily
 
"Fir5tSight" <[email protected]> a écrit dans le message de (e-mail address removed)...

| I have an existing method as follows:
|
| public void InsertScan(int aDistributionCommonInstanceID)
|
| Now I'll need to add a parameter, so it should look like the following:
|
| public void InsertScan(int aDistributionCommonInstanceID, bool bCore)
|
| I want to make this new parameter OPTIONAL as I don't want to change
| any existing code. Could anyone advise me on how?

Optional parameters are not available in C#, you need to overload the
method.

public void InsertScan(int aDistributionCommonInstanceID)
{
InsertScan(aDistributionCommonInstanceID, false);
}

public void InsertScan(int aDistributionCommonInstanceID, bool bCore)
{
...
}

Joanna
 
Back
Top