问题
I have an IEnumerable which contains differences of two files. I want to show these differences in a message box.
I tried to convert it with the toArray() method and with the toString() method.
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);
When I run the code I don't get the expected differences but rather this: "System.String[]System.Linq.Enumerable+d__73`1[System.String]"
回答1:
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
来源:https://stackoverflow.com/questions/57205328/how-to-convert-an-ienumerable-into-a-string-to-put-it-in-a-message-box-in-c