I hate having to do this everywhere:
DataSet ds = dataLayer.GetSomeData(1, 2, 3);
if(ds != null){
if(ds.Tables.Count > 0){
DataTable dt = ds.Tables[0];
foreach(DataRow dr in dt.Rows){
//Do some processing
}
}
}
Instead I usually use the following Extension Method:
public static IEnumerable DataRows(this DataSet current){
if(current != null){
if(current.Tables.Count > 0){
DataTable dt = current.Tables[0];
foreach(DataRow dr in dt.Rows){
yield return dr;
}
}
}
}
So the first example then becomes:
foreach(DataRow row in ds.DataRows()){
//Do some processing
}
Yay, Extension Methods!