Mainly extension methods are used for Code Reusability. So we can simply create one extention method for dataset is valid or not and re-use the across the application
- public static class ExtensionMethods {
- public static bool IsValidDataSet(this DataSet dataSet) {
- if (dataSet != null && dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0) {
- return true;
- }
- return false;
- }
- }
We can call like:
- ExtensionMethods.IsValidDataSet(dataset)
- {
- ///logic here
- }
- else
- //logic here
