473,799 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ValidatingReser vation()

{

ValidReservatio n.Fill(dtValidR eservation, DropDownListFil eID.SelectedVal ue);

int i = 0; bool boolResult = false;

DateTime r1start = Convert.ToDateT ime(BasicDatePi ckerFromDate.Se lectedDate),

r2start = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDdate "]),

r1end = Convert.ToDateT ime(BasicDatePi ckerToDate.Sele ctedDate),

r2end = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["EndDdate"]) ;
if (dtValidReserva tion.Rows.Count == 0) return true;

else foreach( int i in dtValidReservat ion.Rows[i])

{

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

if(boolResult) break;

}

return boolResult;

}
Sep 15 '07 #1
2 1473
Hi again,
I rewrite my code and It is working now. But I need to enhance it more of
possible ...
Thanks in advance.
bool ValidatingReser vation()

{

ValidReservatio n.Fill(dtValidR eservation, DropDownListFil eID.SelectedVal ue);

bool boolResult = false; int i=0;

if (dtValidReserva tion.Rows.Count == 0) return false;

else foreach( DataRow row in dtValidReservat ion.Rows)

{

boolResult = (Convert.ToDate Time(BasicDateP ickerFromDate.S electedDate) ==
Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDate"])) ||
(Convert.ToDate Time(BasicDateP ickerFromDate.S electedDate) >
Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDate"]) ?
Convert.ToDateT ime(BasicDatePi ckerFromDate.Se lectedDate) <=
Convert.ToDateT ime(dtValidRese rvation.Rows[i]["EndDate"]) :
Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDate"]) <=
Convert.ToDateT ime(BasicDatePi ckerToDate.Sele ctedDate));

i++;

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

}

return boolResult;

}

"Tamer Ibrahim" <ca*******@yaho o.co.ukwrote in message
news:ep******** ******@TK2MSFTN GP05.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 ValidatingReser vation()

{

ValidReservatio n.Fill(dtValidR eservation,
DropDownListFil eID.SelectedVal ue);

int i = 0; bool boolResult = false;

DateTime r1start =
Convert.ToDateT ime(BasicDatePi ckerFromDate.Se lectedDate),

r2start = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDdate "]),

r1end = Convert.ToDateT ime(BasicDatePi ckerToDate.Sele ctedDate),

r2end = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["EndDdate"]) ;
if (dtValidReserva tion.Rows.Count == 0) return true;

else foreach( int i in dtValidReservat ion.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...@yaho o.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 ValidatingReser vation()

{

ValidReservatio n.Fill(dtValidR eservation, DropDownListFil eID.SelectedVal ue);

int i = 0; bool boolResult = false;

DateTime r1start = Convert.ToDateT ime(BasicDatePi ckerFromDate.Se lectedDate),

r2start = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["StartDdate "]),

r1end = Convert.ToDateT ime(BasicDatePi ckerToDate.Sele ctedDate),

r2end = Convert.ToDateT ime(dtValidRese rvation.Rows[i]["EndDdate"]) ;

if (dtValidReserva tion.Rows.Count == 0) return true;

else foreach( int i in dtValidReservat ion.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
2440
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 something like: // Iterate whole collection foreach (object in collection) // Iterate over all objects with the "open" flag set
4
1487
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( int i = 0; i < dSMspComposition.Tables.Rows.Count; i++ ) compositionList.Add(dSMspComposition.Tables.Rows);
9
2810
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 and for to enumerate the contents of the array. Also as well as explaining the differences could you explain why the foreach messagebox isn't working below. Many TIA.
5
2766
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 }; foreach (uint x in vals) Console.WriteLine(x);
8
2537
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()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'. I tried to change method signature to
6
5134
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 a dictionary obtaining the next key and value on each iteration. The following doesn't work foreach ( string key in MyDictionary.Keys , object value in
8
1435
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 set of all possible combinations of first and last name.
4
2567
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 makes me infer that you think foreach is enirely useless for composite structures. I will address the subject text, because that makes the most sense to me :-) Take the following class public class MyTreeNode : IEnumerable<MyTreeNode> {
9
2570
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 dialog with several such User Controls. Each custom control has a property for COM port name (serial port). Each custom control has a method for writing the settings. The user control has a GetEnumeration structure so it can be easily referenced...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.