473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

foreach and public GetEnumerator method

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.Selecte dDate),

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

r1end = Convert.ToDateTime(BasicDatePickerToDate.SelectedD ate),

r2end = Convert.ToDateTime(dtValidReservation.Rows[i]["EndDdate"]) ;
if (dtValidReservation.Rows.Count == 0) return true;

else foreach( int i in dtValidReservation.Rows[i])

{

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

if(boolResult) break;

}

return boolResult;

}
Sep 15 '07 #1
2 1452
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.Select edDate) ==
Convert.ToDateTime(dtValidReservation.Rows[i]["StartDate"])) ||
(Convert.ToDateTime(BasicDatePickerFromDate.Select edDate) >
Convert.ToDateTime(dtValidReservation.Rows[i]["StartDate"]) ?
Convert.ToDateTime(BasicDatePickerFromDate.Selecte dDate) <=
Convert.ToDateTime(dtValidReservation.Rows[i]["EndDate"]) :
Convert.ToDateTime(dtValidReservation.Rows[i]["StartDate"]) <=
Convert.ToDateTime(BasicDatePickerToDate.SelectedD ate));

i++;

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

}

return boolResult;

}

"Tamer Ibrahim" <ca*******@yahoo.co.ukwrote in message
news:ep**************@TK2MSFTNGP05.phx.gbl...
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.Selecte dDate),

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

r1end = Convert.ToDateTime(BasicDatePickerToDate.SelectedD ate),

r2end = Convert.ToDateTime(dtValidReservation.Rows[i]["EndDdate"]) ;
if (dtValidReservation.Rows.Count == 0) return true;

else foreach( int i in dtValidReservation.Rows[i])

{

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

if(boolResult) break;

}

return boolResult;

}


Sep 15 '07 #2
simplify and display ur code in a more brief way, almost pseudo-codel
like, so what it is not considered a homework

On Sep 15, 8:40 pm, "Tamer Ibrahim" <camel7...@yahoo.co.ukwrote:
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.Selecte dDate),

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

r1end = Convert.ToDateTime(BasicDatePickerToDate.SelectedD ate),

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

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

else foreach( int i in dtValidReservation.Rows[i])

{

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

if(boolResult) break;

}

return boolResult;

}- Hide quoted text -

- Show quoted text -

Sep 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Barnett | last post by:
I have a collection which I need to navigate through in several different ways. Is there any way to structure my class such that I can have several different iterators? Ideally, I'd like to do...
4
by: tony | last post by:
Hello I use foreach when I have a container of some kind for example an array or ArrayList. But in this case is it really possible to use foreach. In case it is how would I write it. for(...
9
by: garyusenet | last post by:
I'm a bit confused about the differences of these two commands (what is the right word for commands here?) when used to enumerate the contents of an array. The below example uses both foreach...
5
by: james | last post by:
Hey Guys, Would anyone mind explaining why a foreach will implicitly do unsafe casts, and if there is a way to turn this off? Here is an example: ulong vals = new ulong { ulong.MaxValue };...
8
by: Andrus | last post by:
Code below causes error in class definition line .....Isolator<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Myapp.Isolator<T>.GetEnumerator()'...
6
by: John A Grandy | last post by:
Is it possible to write a foreach so that it simultaneously iterates through two collections ( or two properties of the same collection ) ? Following is *only meant as an example* : -- iterate...
8
by: =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?= | last post by:
An example of a slightly more complicated class might be to have a collection of first names, and a collection of last names in your class. The IEnumerable functions then could return the complete...
4
by: Peter Morris | last post by:
I am not sure what you are asking. You seem to be asking how to implement a plain IEnumerable on a composite structure, but then your example shows a flat structure using "yield". Your subject...
9
tlhintoq
by: tlhintoq | last post by:
Situation: A Windows Form with a single User Control containing 4 custom controls. This lets me drop the User Control on its own form to make it a dialog, or make it part of a larger configuration...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.