c# - 如何获取 DataTable 一行中的最后一个单元格?

标签 c#

    foreach(DataRow row in dt.Rows)
    {
       foreach(var cell in row.ItemArray)
       {
          builder.Append(cell.ToString());
          if(cell != row.lastcell)
             builder.Append("\t");
       }
       builder.Append(Environment.NewLine);
    }

我需要确保单元格!=行中的最后一个单元格

我该怎么做?

最佳答案

你不需要那样做。只需使用 string.Join 代替:

string[] strings = Array.ConvertAll(row.ItemArray, x => x.ToString());
builder.Append(string.Join("\t", strings);

关于c# - 如何获取 DataTable 一行中的最后一个单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4503368/

相关文章:

c# - RavenDB 中的集合操作

c# - ASP.net MVC4 中 Html.BeginForm 中多个按钮的问题

c# - 命名空间 'SQLite' 中不存在类型或命名空间名称 'System.Data'

c# - 如何在 ListView 中显示列表项?

c# - 使用 LdapConnection 枚举 AD

c# - 替换 lambda 表达式中的参数

c# - 如何制作类似于 Visual C# 2008 属性窗口的东西?

c# - NLog 有时不写入文件

c# - 使用 ASP.NET MVC 在 View 的 EditorFor() 方法中显示 ViewBag 的值

c# - property.setting 值存储在 c# windows 应用程序中