码迷,mamicode.com
首页 > Windows程序 > 详细

C# 参数可选特性

时间:2019-07-11 12:21:55      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:就是   hello   默认   com   string   tput   htm   ring   方法   

1.定义方法

public string Welcome(string name, int a = 0 ,int b = 1)

{

return HttpUtility.HtmlEncode("Hello a is: " + a + ", b is: " + b);
}

此方法a和b参数的传参方式就是参数可选特性,

即调用welcome方法不对a,b参数传值时,a参数默认值为0,b参数默认值为1.

2.方法调用

 Welcome("test",b:666);

a参数可以不传,由此可见参数可选特性使得方法调用更加灵活方便。

C# 参数可选特性

标签:就是   hello   默认   com   string   tput   htm   ring   方法   

原文地址:https://www.cnblogs.com/SanBu-WuGui/p/11169065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!