首页 > 其他 > 详细

1.7 移除对参数的赋值动作

时间:2017-08-10 17:40:41      阅读:147      评论:0      收藏:0      [点我收藏+]

【1】源代码

 1 int disCount(int inputVal, int quantity, int yearToDate)
 2 {
 3     if (inputVal > 50)
 4     {
 5         inputVal -= 2;
 6     }
 7     if (quantity > 100)
 8     {
 9         inputVal -= 1;
10     }
11     if (yearToDate > 10000)
12     {
13         inputVal -= 4;
14     }
15     return inputVal;
16 }

【2】移除对参数的赋值动作

 1 // 以临时变量取代对参数的赋值动作
 2 int disCount(int inputVal, int quantity, int yearToDate)
 3 {
 4     int result = inputVal;
 5     if (inputVal > 50)
 6     {
 7         result -= 2;
 8     }
 9     if (quantity > 100)
10     {
11         result -= 1;
12     }
13     if (yearToDate > 10000)
14     {
15         result -= 4;
16     }
17     return result;
18 }

【3】总结

代码对一个参数进行赋值。以一个临时变量取代该参数的位置。

 

Good Good Study, Day Day Up.

顺序 选择 循环 总结

1.7 移除对参数的赋值动作

原文:http://www.cnblogs.com/Braveliu/p/7340298.html

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