C # The default parameters make the code more concise and clear, and keep up with the times.

Source: Internet
Author: User

When there was no default parameter in the past, many constructor will be written to make it easier for others to call our code. For example, the following code is pasted on a query method:

Public DataTable Search (string search)
{
Return Search (string. Empty, search, null, null, string. Empty );
}

Public DataTable Search (string search, string [] roleIds)
{
Return Search (string. Empty, search, roleIds, null, string. Empty );
}

Public DataTable Search (string search, string [] roleIds, bool? Enabled)
{
Return Search (string. Empty, search, roleIds, null, string. Empty );
}

Public DataTable Search (string search, string [] roleIds, string auditStates)
{
Return Search (string. Empty, search, roleIds, null, auditStates );
}

Public DataTable Search (string search, string [] roleIds, bool? Enabled, string auditStates)
{
Return Search (string. Empty, search, roleIds, enabled, auditStates );
}
 

After using the default parameters, how can this part of code be simplified?

Public DataTable Search (string search = null, string [] roleIds = null, bool? Enabled = true, string auditStates = null)
{
Return Search (string. Empty, search, roleIds, enabled, auditStates );
}
Wow, a line of code is enough, so many constructors are not needed. The code is much more concise and refreshing.

New technologies often increase production efficiency.

 

With permission management and workflow management, one person can do only a few things well.

From: permission management system component source code, professional permission design [Business Edition]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.