Recursive - the last line of the table data is deleted table

Recursion, it is to call their own.

/// <summary>
/// 递归-删除table表中的最后一行空数据
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static DataTable getNoLastWhiteRow(DataTable dt)
{
    bool res = false;
    if(string.IsNullOrEmpty(dt.Rows[dt.Rows.Count - 1][dt.Columns[0].ColumnName].ToString()))
    {
        dt.Rows.RemoveAt(dt.Rows.Count - 1);
        if (!res)
        {
            getNoLastWhiteRow(dt);
        }
    }
    else
    {
        res = true;
    }
    return dt;
}

 

Guess you like

Origin www.cnblogs.com/wjtstudy/p/11649545.html