2

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

In VB6, 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?

CJ7
  • 22,579
  • 65
  • 193
  • 321
  • Possible dupe: http://stackoverflow.com/questions/199761/how-can-you-use-optional-parameters-in-c - fixed. –  May 12 '10 at 10:34

4 Answers4

1

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.

Jack
  • 292
  • 1
  • 5
0

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

Echilon
  • 10,064
  • 33
  • 131
  • 217
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
0

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.

MUG4N
  • 19,377
  • 11
  • 56
  • 83
0

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

Oded
  • 489,969
  • 99
  • 883
  • 1,009