一行代码从表中选取N行到另一个表

private void Form1_Load(object sender, EventArgs e)

{
            DataTable dt = new DataTable();
            dt.Columns.Add("NUMBER");
            dt.Columns.Add("COUNTRY");
            dt.Rows.Add(1, "PAK");
            dt.Rows.Add(2, "IND");
            dt.Rows.Add(3, "USA");
            dt.Rows.Add(4, "UK");
            dt.Rows.Add(5, "BAN");
            dt.Rows.Add(6, "RSA");
            dt.Rows.Add(7, "CN");
            dt.Rows.Add(8, "AUS");

// the below function will return top 5 rows of datatable and assign to newly created datatable object
            DataTable dt_Top_N_Rows = Top_N_Rows(dt, 5);
        }

private DataTable Top_N_Rows(DataTable dt, int NRows)
        {
            return dt.Rows.OfType<DataRow>().ToList().Take(NRows).CopyToDataTable();
        }

上一篇:jvm内存模型-和内存分配以及jdk、jre、jvm是什么关系(阿里,美团,京东)


下一篇:Bug的严重等级和优先级别与分类