0

I have the following method signature where I want to give a default value to one of my parameters but I dont want to give any default value to the other parameter leadSourceStatus

protected PromotionCatalogResponseRootObject GetVideoPromotionCatalog(PromotionCatalogTypes catalogType = PromotionCatalogTypes.RESIDENTIAL, LeadSourceStatus leadSourceStatus)

But when I try this, I get error

Optional parameters must appear after all required parameters

What will be the best way to deal with this?

Huma Ali
  • 1,759
  • 7
  • 40
  • 66
  • 3
    Swap the parameters. Parameters with a default value, must be defined after the parameters that doesn't have a default value. – Jeroen van Langen Sep 22 '16 at 11:45
  • 2
    Did you read the error? If you have two parameters, optional parameter should be the second. If you have three parameters. optional parameter should be the third. So, optional parameters should appear AFTER all required parameters. – Khalil Khalaf Sep 22 '16 at 11:45
  • Possible duplicate of [optional parameters must appear after all required parameters in c#](http://stackoverflow.com/questions/27316789/optional-parameters-must-appear-after-all-required-parameters-in-c-sharp) – NathanOliver Sep 22 '16 at 11:56

2 Answers2

5

The best way to deal with it is to do what it told you to do, and put the optional param at the end:

protected PromotionCatalogResponseRootObject GetVideoPromotionCatalog(LeadSourceStatus leadSourceStatus, PromotionCatalogTypes catalogType = PromotionCatalogTypes.RESIDENTIAL)
rory.ap
  • 34,009
  • 10
  • 83
  • 174
2

Just put optional parameter at then end as error message said

protected PromotionCatalogResponseRootObject GetVideoPromotionCatalog(LeadSourceStatus leadSourceStatus, PromotionCatalogTypes catalogType = PromotionCatalogTypes.RESIDENTIAL)
Mostafiz
  • 7,243
  • 3
  • 28
  • 42