Beginner C # code Simplicity-function Chapter

Source: Internet
Author: User

1. Extracting MVC HtmlHelper from HTML code


<td class = "Noborder NOPADDINGV" >
<div class = "AlignCenter" >
<a href= "/home/index" >
Src= ". /.. /resouces/images/agile/menu/campass48.png "alt =" Site Map "
title = "Sitemap" class = "ImageLink"/></a><br/>
Site Map
</div>
</td>
<td class = "Noborder NOPADDINGV" >
<div class = "AlignCenter" >
<a href= "/home/index" target = "_blank" >
Src= ". /.. /resouces/images/agile/help/help48.png "alt =" Help "title ="
Help "class =" ImageLink "/></a><br/>
Help
</div>
</td>

After the change:

@Html. Menuimagebuttonv ("Sitemap", False, "/home/index",
".. /.. /resouces/images/agile/menu/campass48.png ")
@Html. Menuimagebuttonv ("Help", "true", "/home/index",
".. /.. /resouces/images/agile/help/help48.png ")
This technique: When two pieces of code are the same, can become a function and two calls, the same part is the letter
Number, the different part is the invocation parameter.


2. The simplicity of the function interface:

Not writing a function is all right, bad function interface is still not concise. Here is a newly-changed
Example:

@Html. ImageLink ("Burn Chart", True,
".. /.. /resouces/images/agile/currentsprint/burndowndata16.png "," Icons ",
False, "/agile/currentsprint/burndowndata", NULL, NULL)

@Html. ImageLink ("Iteration plan", True,
".. /.. /resouces/images/agile/sprints/index16.png "," Icons ", False,
"/agile/sprints/index", NULL, NULL)

...
Modified result (another piece of code):

@Html. ImageLink ("Iteration plan", "/agile/sprints/index", true)//This true some
The place was not quite the same so it stayed.
@Html. ImageLink ("Iteration Story", "/agile/sprints/sprintstories", True)
This technique: If some parameters change when the function is called repeatedly, some parameters are basically the same ("Icons",
True, False, null .... ), which should turn into optional parameters and set default values.

Beginner C # code Simplicity-function Chapter

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.