【发布时间】:2014-10-04 18:17:30
【问题描述】:
我有一个包含整数和字符串的简单结构列表。
结构:
public struct ErrorType
{
public int RowNumber;
public int ColumnNumber;
public string ErrorMessage;
}
On of My methods 返回这些结构的列表。 我想将列表中的每个成员转换为其字符串形式并用逗号分隔,以便 List 现在是一个字符串数组。我可以编写一个函数来手动执行此操作,但我更喜欢使用 linq 来获得更清洁的解决方案。
拥有字符串数组,我将使用
将其写入文件 string path = @"c:\temp\MyTest.txt";
// This text is added only once to the file.
if (!File.Exists(path))
{
// Create a file to write to.
List<ErrorType> ErrorTypesList = GetErrors();
//do some work to iterate over the members and do a string.join after
string[] ErrorListArray = ErrorTypesList.foreach( e => { });
File.WriteAllLines(path, createText);
}
是否有人对如何填写 foreach 有什么建议,以便它以 ToString 形式返回每个成员,后跟逗号?
【问题讨论】: