2010-05-12 76 views
2

有没有一种方法可以简化在C#中使用VS2005添加重载方法的过程?C#中的重载方法

在VB6中,我只是添加了一个可选参数的函数,但在C#中,我必须用这个新参数输入一个全新的方法吗?

+0

可能的重复:http://stackoverflow.com/questions/199761/how-can-you-use-optional-parameters-in-c - 修复。 – 2010-05-12 10:34:13

回答

1

与c#2.0只有一种代码生成工具的方式。 resharper可以做到这一点。与C#4.0可选参数也是可能的。

0

是的。在C#4.0中,您可以使用可选参数,但在C#2.0中,您必须手动指定它们。

0

你可以用.NET 4.0做到这一点:

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

在早期版本中,你需要编写单独的方法。