For the below code, when i display date from the "for" loop, I get the expected answer but when I store the date in list, I get some other output.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class dateshow
{
static void Main(string[] args)
{
List<DateTime> allDates = new List<DateTime>();
DateTime startDate = Convert.ToDateTime("2018-03-03");
DateTime endDate = Convert.ToDateTime("2018-03-15");
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
{
allDates.Add(date);
Console.WriteLine(date);
Console.WriteLine(allDates); //ERROR : doesnt display the dates, instead displays System.Collections.Generic.List`1[System.DateTime]
}
}
}
}
Where am I going wrong?