C#不支持参数默认值,如果要实现相同功能,可以使用函数重载的方法模拟实现。
如:
void MsgBox(string msg, string title)
{
MessageBox.Show(msg, title);
}
void MsgBox(string msg)
{
MsgBox(msg, "消息"); // "消息" 即是 title 参数的默认值。
}
C#中的函数参数能不能有默认值的解决方法
最新推荐文章于 2022-02-06 12:45:04 发布