DateTime sdate=Convert.ToDateTime(amcsdate.Text);
DateTime edate=Convert.ToDateTime(amcedate.Text);
DateTime i;
for(i=sdate;i<=edate;i=i.AddMonths(1))
{
Response.Write(i);
}
above coding works fine . how to store the values of i in different variable like d1,d2,d3 etc.
Example :
sdate = jul 03 2006
edate = jul 03 2007
now i want to store the value of i in
d1,d2,d3,d4.........etc till i <= edate . after getting the values of d1,d2 etc i will be storing in database .
my table format :
d1 d2 d3 d4 etc ............
jul 03 2006 Aug 03 2006 Sep 03 2006 Oct 03 2006

doubt in FOR loop urgent .
Confused4130
ArrayList list = new ArrayList();
for(i=sdate;i<=edate;i=i.AddMonths(1))
{
list [ i ] = <store the value you want>;
}
F. Gsell
Let's try that again....
ArrayList list = new ArrayList();
for(i=sdate;i<=edate;i=i.AddMonths(1))
{
list.Add(<store the value you want>);
}
Using list
to store values will cause an ArgumentOutOfRangeException unless the array is pre-sized to the correct number of values.
drummstick
If you're using C# v2.0, then instead of using ArrayList you could use List<DateTime>. This is a strongly-typed version of ArrayList. It means that you can go on to do this sort of thing
Console.WriteLine(list[2].Month);
If you try that with list being an ArrayList, you'll get a compiler error. You'd have to cast the elements back to DateTime before doing anything with them. List<> avoids that.