c# 数组拼接、DataTable拼接
2021-05-14 15:29
标签:one int class str bsp span write reac result c# 数组拼接、DataTable拼接 标签:one int class str bsp span write reac result 原文地址:https://www.cnblogs.com/hanglog/p/13124189.html //数组拼接
var intArray_1 = new int[] { 1, 2, 3 };
var intArray_2 = new int[] { 4, 5, 6 };
var result = intArray_1.Concat(intArray_2);
foreach (var item in result)
{
Console.WriteLine(item);
}
//datatable拼接
//创建表头
DataTable dt1 = new DataTable();
dt1.Columns.Add(new DataColumn("姓名",typeof(string)));
dt1.Columns.Add(new DataColumn("年龄", typeof(string)));
dt1.Columns.Add(new DataColumn("班级", typeof(string)));
//添加一行数据
DataRow dr = dt1.NewRow();
dr["姓名"] = "小明";
dr["年龄"] = "18";
dr["班级"] = "三班";
dt1.Rows.Add(dr);
//克隆一个dt
var newDataTable = dt1.Clone();
//添加一行数据
newDataTable.Rows.Add(dr);
//合并两个datatable--用Merge()这个方法即可
dt1.Merge(newDataTable);
文章标题:c# 数组拼接、DataTable拼接
文章链接:http://soscw.com/index.php/essay/85668.html