Best practices in developing ASP. NET applications...

Source: Internet
Author: User
  • Remove unusedPrivateFields and functions.
  • Do not cast unnecessarily. Avoid duplicate casts where possible, since there is a cost associated with them.
  • Properties that return arrays are prone to code inefficiencies. Consider using a collection or making this a method.
  • To test for empty String S, check ifString. Length Is equal to zero. constructs such "". Equals (somestring) And String. Empty. Equals (somestring) Are less efficient than testing String Length. replace these with checks Somestring. Length = 0 .
  • Methods In the same type that differ only by return type can be difficult for developers and tools to properly recognize. when extending a type, be sure not to define new methods that differ from base type methods only by type.
  • UseStringbuilderInsteadStringTypesStringManipulation.
  • use string. format instead of concatenating and appending string S.
  • UseType. tryparseRatherConvert. todestinationtype (). For example, useInt. tryparse ()RatherConvert. toint32 ()Which might throw an exception.
  • OverrideEquals ()Method wherever applicable in your classes.
  • consider passing base types as parameters-using base types as parameters to Methods improves re-use of these methods if you only use methods & properties from the parameter's base class. e. g. use stream instead of filestream as a parameter when only calling stream. read () , this makes the method work on all kind of stream S instead of just file streams.
  • Do not catch General Exception types-You shoshould not catchExceptionOrSystemexception. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You shocould catch only those exceptions that you can handle gracefully.
  • Use properties instead of visible instance fields.
  • Follow the same naming conventions accross the solution.
  • Remove unwanted commented code, indent code properly.
  • Use curly braces with inIfStatement, even if there is a single statement inIfBlock. This will provide better readability.
  • Make sure to refactor your code to move the duplicated code to Common Reusable functions.
  • Move one time control settings into. AspxPage rather than having them in the code behind inIf (! Ispostback)Block.
  • Use inheritance wherever possible, which enables code reuse and also when CES The amount of code we have to write and test.
  • Move the reusable JavaScript Functions to an external. JsFile instead of having them on the page.
  • For controls that are declaratively specified on the page, tie the event handlers to the controls events on the ASPX page rather than initializing them in the codebehind. if the controls are built dynamically, then we do not have a choice.
  • Make sure to checkNullS when using any type retrieved from a session, querystring or a database to avoidNullreferenceexceptions.
  • UseForeachLoop instead of usingForLoop which may lead to out of boundary run time limits tions.
  • 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.