foreach and public GetEnumerator method

Discussion in 'ASP .Net' started by Tamer Ibrahim, Sep 15, 2007.

  1. 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;

    }
     
    Tamer Ibrahim, Sep 15, 2007
    #1
    1. Advertising

  2. 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;

    }



    "Tamer Ibrahim" <> wrote in message
    news:...
    > 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;
    >
    > }
    >
    >
     
    Tamer Ibrahim, Sep 15, 2007
    #2
    1. Advertising

  3. Tamer Ibrahim

    Nick Chan Guest

    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" <> wrote:
    > 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;
    >
    >
    >
    > }- Hide quoted text -
    >
    > - Show quoted text -
     
    Nick Chan, Sep 17, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,391
    smith
    Dec 8, 2004
  2. TPS
    Replies:
    2
    Views:
    506
    MS News \(MS ILM\)
    Aug 15, 2003
  3. SpamProof
    Replies:
    0
    Views:
    593
    SpamProof
    Oct 21, 2003
  4. Kevin Spencer
    Replies:
    2
    Views:
    3,318
    Kevin Spencer
    Sep 15, 2004
  5. kaoskoder
    Replies:
    0
    Views:
    239
    kaoskoder
    Jan 27, 2004
Loading...

Share This Page