相似命名的字符串高效拼接

static void Main(string[] args)
{
    new Program();
}
public string String1 = "aaaa";
public string String2 = "bbbb";
public string String3 = "cccc";
public string String4 = "dddd";
public string String5 = "eeee";
public string String6 = "ffff";

public Program()
{
    string temp = "";
    Type type = this.GetType();
    for (int i = 1; i < 7; i++)
    {
        FieldInfo fi = type.GetField("String" + i.ToString());
        temp += fi.GetValue(this).ToString();
    }
    Console.WriteLine("111");
    Console.WriteLine(temp);
    Console.Read();
}

Result:

aaaabbbbccccddddeeeeffff
posted @ 2018-12-18 16:36  Kyle0418  阅读(170)  评论(2编辑  收藏  举报