简体   繁体   中英

Setting the default value for enum parameter

I have a method that accepts an enum value as an input parameter. How do I set the default value for this enum param?

Below code shows how I set it now but if no value defined while calling this method, it's not using the default value. It uses another value. Any idea why?

public string MyFunction(string param1, MyEnum param2 = MyEnum.MyDefaultValue)
{
   // Do something...
}

I call this function without specifying a value for param2 -- see below:

... // Some code
var response = MyFunction("Hello World!"); // Purposely not specifying the param2 value so it uses the default one

When I hit my break point in MyFunction after calling it without specifying a value for param2 , I see that it does NOT use the default value.

Any idea why?

根据评论,事实证明这是在接口中设置的不同默认值,并且它是由依赖注入器应用的

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