Welcome to the series of posts about the .NET Framework 4.0.
Let’s start by the first feature that has been available for years on Visual Basic development and now is available for C# programs: Optional parameters on methods.
Take a look on the following code snippet:
public void MyMethod(int a = 123)
The simple method above accepts an integer as parameter. You may have noticed the existence of a value being assigned to the parameter “a”. When a default value is assigned on the method declaration the parameter becomes optional and there is no obligation of passing any value to the method.
Assuming the method calls below, check the results of them:
MyMethod(12); // Output: 12
MyMethod(); // Output: 123