Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Parameters for method in c#

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?

like image 280
Huma Ali Avatar asked Nov 27 '25 01:11

Huma Ali


2 Answers

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)
like image 65
rory.ap Avatar answered Nov 29 '25 22:11

rory.ap


Just put optional parameter at then end as error message said

protected PromotionCatalogResponseRootObject GetVideoPromotionCatalog(LeadSourceStatus leadSourceStatus, PromotionCatalogTypes catalogType = PromotionCatalogTypes.RESIDENTIAL)
like image 28
Mostafiz Avatar answered Nov 30 '25 00:11

Mostafiz