我正在尝试创建一个包含行数 > 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);
}
}
}
输出是:
正如你所看到的,这不是我想要的。即使当我写为字符串时,它也不会显示\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/