Does optional parameter and optional attribute not

2020-05-09 22:41发布

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条回答
女痞
2楼-- · 2020-05-09 23:01

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)
{
}
查看更多
登录 后发表回答