You can't just treat a List<DateTime> as an array of DateTime values, it's more than that. You have to convert it, which is simple to do. But - you don't want to use strings, they really don't compare well when dealing with date based info!
There are three ways to deal with this:
1) Change the method to return an array of DateTime values:
public DateTime[] GetDatesBetween(DateTime startDate, DateTime endDate)
{
List<DateTime> allDates = new List<DateTime>();
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
allDates.Add(date);
return allDates.ToArray();
}
2) Use a List outside the method:
protected void Button1_Click1(object sender, EventArgs e)
{
DateTime starting=new DateTime();
starting=DateTime.ParseExact(datepicker.Value,"dd-MM-yyyy",null);
DateTime ending=new DateTime();
ending=DateTime.ParseExact(date2.Value,"dd-MM-yyyy",null);
List<DateTime> dates = GetDatesBetween(starting, ending);
}
3) Convert the List to an array outside the method:
protected void Button1_Click1(object sender, EventArgs e)
{
DateTime starting=new DateTime();
starting=DateTime.ParseExact(datepicker.Value,"dd-MM-yyyy",null);
DateTime ending=new DateTime();
ending=DateTime.ParseExact(date2.Value,"dd-MM-yyyy",null);
DateTime[] dates = GetDatesBetween(starting, ending).ToArray();
}