Home
Do you put optional parameters at the end?
  v1.0 Posted at 27/04/2018 9:49 AM by Tiago Araujo
Optional parameters should be placed at the end of the method signature as optional ones tend to be less important. You should put the important parameters first.

public void SaveUserProfile(
[Optional] string username,
[Optional] string password,
string firstName,
string lastName,
[Optional] DateTime? birthDate)

Figure: Bad Example - Username and Password are optional and first - they are less important than firstName and lastName and should be put at the end


public void SaveUserProfile(
string firstName,
string lastName,
[Optional] string username,
[Optional] string password,
[Optional] DateTime? birthDate)

Figure: Good Example - All the optional parameters are the end


Note: When using optional parameters, please be sure to use named para meters

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.