如何从 Datarow.ItemArray 中删除一些列

How to remove some columns from Datarow.ItemArray

IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
sb.AppendLine(string.Join(",", fields));

从上面的代码中,我得到了这个输出

#,1104,466161,1,,AUD,190910,876.65,,SO,NOW,,,,,,,,,,,,,,
D,,,,,,,OUT,,,,AUD,,,,0,,0,N,,,,,,

但我的预期输出是

#,1104,466161,1,,AUD,190910,876.65,,SO,NOW,,,,,
D,,,,,,,OUT,,,,AUD,,,,0,,0,N,,,,,,

想去掉第一行'NOW'后面的一些逗号

这样您就可以删除所有结尾的逗号:

var fields = row.ItemArray;
sb.AppendLine(string.Join(",", fields).TrimEnd(','));

这样你可以获取一定数量的列:

var fields = row.ItemArray.Take(10);
sb.AppendLine(string.Join(",", fields));