简体   繁体   中英

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?

处理它的最好方法是按照它告诉您的操作进行操作,并在最后放置可选参数:

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

只需将可选参数放在结尾,然后出现错误消息

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM