In C#, what is the best way to test if a dataset is empty?

后端 未结 6 773
無奈伤痛
無奈伤痛 2021-01-12 13:59

I know you can look at the row.count or tables.count, but are there other ways to tell if a dataset is empty?

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 14:37

    #region Extension methods
    
    public static class ExtensionMethods
    {
        public static bool IsEmpty(this DataSet dataSet)
        {
            return dataSet == null || dataSet.Tables.Count == 0 || !dataSet.Tables.Cast().Any(i => i.Rows.Count > 0);
        }
    }
    
    #endregion
    

提交回复
热议问题