using System; using System.Data; using System.Data.SqlClient; namespace App{ class MyClass{ public static void Main(string[] args){ //DataTable dt = new DataTable(); int[] id = { 4, 5, 1, 3, 2, 7, 6 }; string[] name = {"Tom","Jack","HelloWorld","Visual Studio","Gril","Timmy","Geo" }; DataTable dt = new DataTable("Table_New"); //DataColumn dc = new DataColumn(); dt.Columns.Add("id",typeof(int)); dt.Columns.Add("name",typeof(string)); for(int i=0;i<id.Length;i++){ dt.Rows.Add(new object[]{id[i],name[i]});//添加一个数组 } //遍历dataTables; for(int i=0;i<id.Length;i++){ Console.WriteLine(dt.Rows[i]["name"]); } } } }