Do you put optional parameters at the end?
Updated by Brook Jeynes [SSW] 2 years ago. See history
123
<introEmbed
body={<>
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: 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: Figure: Good example - All the optional parameters are the end
Note: When using optional parameters, please be sure to use named para meters
Categories
Related rules
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.