Does optional parameter and optional attribute not supported together?

佐手、 提交于 2020-01-11 14:34:30

问题


public void ObjTest(StringBuilder sb, List<string> list, int i = 0,  [Optional] string bs)
{
    ......
 }

The above code throwing compilation error " Optional parameters must appear after all required parameters ". Does optional parameter and optional attribute not supported together in same method parameter, but it allows params arry after optional paramer ?


回答1:


You can use them in conjunction but the optional parameter (the language construct) must be the last parameter in the parameter list.

public void X(StringBuilder sb, List<string> list, [Optional] string bs, int i = 0)
{
}


来源:https://stackoverflow.com/questions/25095627/does-optional-parameter-and-optional-attribute-not-supported-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!