如何将两个字符串组合成另一个字符串的名称并调用该字符串? [英] How to combine two strings into the name of another string and call that string?

查看:35
本文介绍了如何将两个字符串组合成另一个字符串的名称并调用该字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

is there any way to simplify this code into a few lines, I have a class with string seq(number) has {get;set} functions. I am getting lucio and textValue from another class.

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; }
    }

推荐答案

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

May be this could help you reducing the 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;
        }
    }

这篇关于如何将两个字符串组合成另一个字符串的名称并调用该字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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