可选参数和可选属性不一起支持吗? [英] Does optional parameter and optional attribute not supported together?

查看:103
本文介绍了可选参数和可选属性不一起支持吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 ?

推荐答案

您可以结合使用它们,但可选参数(语言构造)必须是参数列表中的最后一个参数.

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)
{
}

这篇关于可选参数和可选属性不一起支持吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆