I seem to recall reading there was an important difference between method overloading (and constructor chaining) and optional parameters in C# 4.0, but I haven't been able to locate anything acknowledging any difference.
Are there any important differences between the following two implementations?
First
public void Foo()
{
Foo(String.Empty);
}
public void Foo(string message)
{
Console.WriteLine(message);
}
Second
public void Foo(string message = "")
{
Console.WriteLine(message);
}
I would favour method overloading. There are known versioning issues with optional parameters.
There is a very good article by Jon Skeet here.
Motivation for adding this was making it easier to talk to COM where methods can have many many parameters and less fora new design practice for C# classes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With