foreach and public GetEnumerator method

T

Tamer Ibrahim

Hi,

foreach is not able to iterate through the collection because there is no
public GetEnumerator method

the foreach is not working in this code snippet, How can I resolve this ?



bool ValidatingReservation()

{

ValidReservation.Fill(dtValidReservation, DropDownListFileID.SelectedValue);

int i = 0; bool boolResult = false;

DateTime r1start = Convert.ToDateTime(BasicDatePickerFromDate.SelectedDate),

r2start = Convert.ToDateTime(dtValidReservation.Rows["StartDdate"]),

r1end = Convert.ToDateTime(BasicDatePickerToDate.SelectedDate),

r2end = Convert.ToDateTime(dtValidReservation.Rows["EndDdate"]) ;


if (dtValidReservation.Rows.Count == 0) return true;

else foreach( int i in dtValidReservation.Rows)

{

boolResult = (r1start == r2start) || (r1start > r2start ? r1start <= r2end :
r2start <= r1end);

if(boolResult) break;

}

return boolResult;

}
 
T

Tamer Ibrahim

Hi again,
I rewrite my code and It is working now. But I need to enhance it more of
possible ...
Thanks in advance.
bool ValidatingReservation()

{

ValidReservation.Fill(dtValidReservation, DropDownListFileID.SelectedValue);

bool boolResult = false; int i=0;

if (dtValidReservation.Rows.Count == 0) return false;

else foreach( DataRow row in dtValidReservation.Rows)

{

boolResult = (Convert.ToDateTime(BasicDatePickerFromDate.SelectedDate) ==
Convert.ToDateTime(dtValidReservation.Rows["StartDate"])) ||
(Convert.ToDateTime(BasicDatePickerFromDate.SelectedDate) >
Convert.ToDateTime(dtValidReservation.Rows["StartDate"]) ?
Convert.ToDateTime(BasicDatePickerFromDate.SelectedDate) <=
Convert.ToDateTime(dtValidReservation.Rows["EndDate"]) :
Convert.ToDateTime(dtValidReservation.Rows["StartDate"]) <=
Convert.ToDateTime(BasicDatePickerToDate.SelectedDate));

i++;

if (boolResult) { Msg.Text += "overlap"; break; }

}

return boolResult;

}
 
N

Nick Chan

simplify and display ur code in a more brief way, almost pseudo-codel
like, so what it is not considered a homework
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top