首页 > Windows开发 > 详细

C# Best Practices - Creating Good Methods

时间:2016-01-14 12:10:42      阅读:203      评论:0      收藏:0      [点我收藏+]

How to Define a Method

Identify the problem => Define the single purpose => Specify the inputs and outputs => State any assumptions => Consider the error that could occur

Build a Method

Signature

public bool PlaceOrder(Product product, int quantity)

Optional accessibility modifier (Default is private)

Return type (void if no value)

Method name

Parameter list (Empty parenthesis if no parameters)

XML Document Comment

Use ///

Summary for method purpose

param for a description of each parameter

Signature Best Practices

Do:

Use a verb

Define the most restricted accessibility possible

Keep the number of parameters to a minimum

Define an XML document comment

Avoid:

Vague terms

Abbreviations

Conjunctions (and/or)

Inconsistent naming

C# Best Practices - Creating Good Methods

原文:http://www.cnblogs.com/lmfy/p/5129672.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!