如何将两个字符串组合成另一个字符串的名称并调用该字符串?

冰立方

有什么方法可以将这段代码简化为几行,我有一个带有字符串seq(number)的类,它具有{get; set}函数。我从另一个班级得到了lucio和textValue。

public static void setCategorySeq(string lucio, string textValue)
    {
        if (lucio == "0") { seq0 = textValue; }
        else if (lucio == "1") { seq1 = textValue; }
        else if (lucio == "2") { seq2 = textValue; }
        else if (lucio == "3") { seq3 = textValue; }
        else if (lucio == "4") { seq4 = textValue; }
        else if (lucio == "5") { seq5 = textValue; }
        else if (lucio == "6") { seq6 = textValue; }
        else if (lucio == "7") { seq7 = textValue; }
        else if (lucio == "8") { seq8 = textValue; }
        else if (lucio == "9") { seq9 = textValue; }
        else if (lucio == "10") { seq10 = textValue; }
        else if (lucio == "11") { seq11 = textValue; }
        else if (lucio == "12") { seq12 = textValue; }
        else if (lucio == "13") { seq13 = textValue; }
        else if (lucio == "14") { seq14 = textValue; }
        else if (lucio == "15") { seq15 = textValue; }
    }
阿德·哈立德(M. Adeel Khalid)

也许这可以帮助您降低LOC。

    public static void setCategorySeq(string lucio, string textValue)
    {
        string[] seq = new string[16];
        for (int i = 0; i <= 15; i++)
        {
            if (lucio == i.ToString())
                seq[i] = textValue;
        }
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将多个字符组合成一个字符串?

如何用另一个字符串的前两个字符替换一个字符串的前两个字符?

我如何将两个字符组合成字符串C#

如何将多个输入行组合成一个字符串?

将两个字符从字符串移动到另一个字符串中出错

将两个字符串中的每个字符串的所有第一个类似的字符放入另一个字符串中

如何测试两个字符串是否同时出现在另一个字符串中?

如何比较两个字符串数组并将匹配值存储在另一个字符串数组中?

如何替换两个字符串,以使一个字符串最终不会替换另一个字符串?

将两个字符串合并为一个字符串

将一个字符串拆分为两个字符串

将两个字符串组合成python中的变量

我想将字符组合成一个字符串

如何将一个字符串分成两个字符串?

如何在Swift 3中将两个字符串(日期和时间)组合成一个新日期

如何从一个字符串中一次读取两个字符并复制到另一个字符串中

两个字符串,并让输入的字母打印另一个字符串中的内容

如何将多个字典组合成一个字符串?(键和值)

在两个字符串之间替换一个字符串

如何将一个字符串数组存储到另一个字符串数组中?

如何将一个字符串插入另一个字符串?

如何将一个字符串值与另一个字符串值进行比较?

如何将一个字符串与另一个字符串匹配并为其返回 true?

swift:如何将一个字符串从textField分配给另一个字符串?

Ember.js 将数据存储中的两个对象组合成一个字符串

如何将多个数组和一个字符串组合成一个数组?

如何将2数组的第一个元素组合成一个字符串数组?

将find_all美丽的汤标签组合成一个字符串

将多个mysql数据组合成一个字符串并用php显示