循环和字符串输出

Hul*_*laz 0 c# string loops

嗨,我有以下代码:

static void CalcWordchange()
{
    List<string[]> l = new List<string[]>
        {
        new string[]{Question1, matcheditalian1},
        new string[]{"Sam", matcheditalian2},
        new string[]{"clozapine", matcheditalian3},
        new string[]{"flomax", matcheditalian4},
        new string[]{"toradol", matcheditalian5},
        };

    foreach (string[] a in l)
    {
        int cost = LevenshteinDistance.Compute(a[0], a[1]);
        errorString = String.Format("To change your input: \n {0} \n into the correct word: \n {1} \n you need to make: \n {2} changes \n ".Replace("\n",      Environment.NewLine),
            a[0],
            a[1],
            cost);
    }
}
Run Code Online (Sandbox Code Playgroud)

每次单击一个按钮时,foreach循环中的文本都会运行并输出一个句子(列表中的最后一项).我想要发生的是将所有5个项目输出到一个字符串中.

我添加了4个新变量(errorString2,3等),但无法解决如何输出它.

任何帮助表示赞赏,谢谢

Ben*_*igt 5

尝试使用StringBuilder对象来收集所有部分.

StringBuilder buildString = new StringBuilder();
foreach (string[] a in l)
{
    int cost = LevenshteinDistance.Compute(a[0], a[1]);
    buildString.AppendFormat("To change your input: \n {0} \n into the correct word: \n {1} \n you need to make: \n {2} changes \n ".Replace("\n",      Environment.NewLine),
        a[0],
        a[1],
        cost);
}
errorString = buildString.ToString();
Run Code Online (Sandbox Code Playgroud)