Justin wrote:
I don't use the foreach statement often so this problem has cought me
off guard. Here is the code:
foreach (int i in EventDates.Items)
{
DateList += EventDates.Items[i].ToString();
}
I get an "invalid cast" error! and I can't seem to find the solution.
Thanks, Justin.
You don't specify the type of EventDates or DateList, but there is (at least)
one thing wrong:
the type in the foreach ("int i" in your case) should be a member of the collection,
not an index!
either change it to:
for (int i = 0; i<EventDates.Items.Count; i++)
DateList += EventDates.Items[i].ToString();
or to:
foreach (DateListItem dli in DateList.Items)
DateList += dli.ToString();
(change the types to the appropriate ones, I had to guess)
The "for" version might be a bit faster than "foreach"!
Hans Kesting