重构方法 [英] Refactoring method

查看:60
本文介绍了重构方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


您好,


我在代码中遵循以下方法。如果将来有条件,我可能会有更多。所以只是想知道如何从维护的角度重新考虑这个代码。

string MyMethod(字符串过滤器)

    {

      StringBuilder sbFilter = new StringBuilder(filter);

解决方案

if(filter.Contains(" A"))sbFilter.Append(" ; X");


以上是if语句和'then'是一行代码。


Hello,

I've following method in the code.I could have some more if conditions in the future. So just wondering how to re-factor this code from a maintenance point of view.
string MyMethod(string filter)
    {
      StringBuilder sbFilter = new StringBuilder(filter);

解决方案

if (filter.Contains("A")) sbFilter.Append("X");

The above is about it where If statement and the 'then' is one line of code.


这篇关于重构方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆