如何将 IEnumerable 转换为字符串以将其放入 C# 中的消息框中?

How to convert an IEnumerable into a string to put it in a message box in c#?

我有一个 IEnumerable,其中包含两个文件的差异。我想在消息框中显示这些差异。

我尝试使用 toArray() 方法和 toString() 方法对其进行转换。

IEnumerable<String> inFirstNotInSecond = file1Lines.Except(file2Lines);
IEnumerable<String> inSecondNotInFirst = file2Lines.Except(file1Lines);

//i also tried this commented line below
//string Diff = new string(inFirstNotInSecond.Take(50).ToArray());

string Diff = inFirstNotInSecond.ToArray().ToString();
string Diff2 = inSecondNotInFirst.ToString();
MessageBox.Show("Difference:" + Diff + Diff2);

当我 运行 代码时,我没有得到预期的差异,而是这样的:"System.String[]System.Linq.Enumerable+d__73`1[System.String]"

List<string> myStrings = new List<string>()
{
    "aaa",
    "bbb",
    "ccc",
};

Console.WriteLine(String.Join(";", myStrings));
// Result:
// aaa;bbb;ccc

Console.WriteLine(String.Join("\n", myStrings));
// Result:
// aaa
// bbb
// ccc