Donnerstag, 2. August 2012 15:36
hi,why my program crashes at these line :
List <DateTime> dt = new List<DateTime>();
foreach (string date in Dates) ///Dates list stores dates like "1/1/2012"
foreach (DateTime dt_ in dt)
if (dt_ > Convert.ToDateTime(End_Date))
else if (dt_ < Convert.ToDateTime(Begin_Date))
if conditions occurs and something removes from list then program crashes.why ?
Donnerstag, 2. August 2012 15:41
This is more a C# forum question, but when you are in a foreach loop, you cannot remove items from collection. Best way is to have another collection and add removable items to it, then after foreach ends, iterate through that collection and the remove them from original collection that way.
Also doing a Convert.ToDateTime everytime for each dt_ is very inefficient, do it once before the loop and assign it ot a variable and use that variable.
Good luck and happy coding.
noorbakhsh حميد نوربخش