c# - 如何在 C# 中的 DataTable 中添加 "String[] or List<String>"作为一个单元格条目?

标签 c# datatable

我正在尝试创建一个包含行数 > 1 的单元格的数据表。 (仅供引用:C# 新手,对 OOPS 一无所知……请友善) 这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.IO;
namespace Excelapp
{
class Program
{
    static void Main(string[] args)
    {
        DataTable table = new DataTable();
        table.Columns.Add("LOCarray",typeof(String[]));
        table.Columns.Add("LOCstring", typeof(String));
        table.Columns.Add("LOClist", typeof(List<String>));


        String[] LOCarray = new String[2] {"Line1","Line2" };
        String LOCstring = "Line1\n\rLine2";
        List<String> LOClist = new List<String>();
        LOClist.Add("Line1");
        LOClist.Add("Line2");

        table.Rows.Add(LOCarray, LOCstring, LOClist);

        }
    }
}

输出是:

DataSet Visualizer enter image description here

正如你所看到的,这不是我想要的。即使当我写为字符串时,它也不会显示\n 字符。

请帮助我。

最佳答案

string[] arr = { "one", "two", "three" };

string arrayValuesWithNewLineSep = string.Join("\n", arr));

关于c# - 如何在 C# 中的 DataTable 中添加 "String[] or List<String>"作为一个单元格条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39917822/

相关文章:

c# - 如何在 C# 中对二维数组进行排序

c# - 这是什么算法?

c# - 在 datagridview 中显示按当前日期过滤的数据 C#

javascript - 在另一个数据表的子行中添加嵌套数据表

R 根据数据帧中的值重复值

C# 内联 lambda 评估

c# - WCF:回调不是异步的

C# 'SerialPort' 不包含采用 6 个参数的构造函数

javascript - 出现错误 - TypeError : DataTable. fnDestroy 不是函数

laravel - 如何在 Laravel 中添加到数据表列的路由链接?