CJ7
CJ7

Reputation: 23295

Overloading methods in C#

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?

Upvotes: 2

Views: 437

Answers (4)

Sam Holder
Sam Holder

Reputation: 32954

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

Upvotes: 0

Oded
Oded

Reputation: 499252

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

Upvotes: 0

MUG4N
MUG4N

Reputation: 19717

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.

Upvotes: 0

Jack
Jack

Reputation: 292

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.

Upvotes: 1

Related Questions