开发者

Overloading methods in C#

Is there a way to simplify the process of adding an overloaded method in C# using VS2005?

In VB开发者_运维技巧6, I would have just added an Optional parameter the function, but in C# do I have to have to type out a whole new method with this new parameter?


with c# 2.0 there is only a way with code generation tools. resharper could do this. with c# 4.0 optional parameters are possible too.


You can do this with .net 4.0:

   1:  public void SendMail(string toAddress, string bodyText, bool ccAdministrator = true, bool isBodyHtml = false)
   2:  {
   3:      // Full implementation here
   4:  }

In earlier version you need to write separate methods.


C# 4.0 has optional parameters - see the programming guide.


Yes. In C# 4.0 you can use optional parameters, but in C# 2.0 you have to specify them manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜