Hey Tadit,
From what i can tell, the reason why your getting "null" date times in your collection is because whatever class your collection of slotsAvailable is...does not have values for those datetimes.
Here is a recreation of your problem...piping the group by output to Console.WriteLine.
public static void Q594720()
{
List<Slots> slotsAvailable = new List<Slots>();
slotsAvailable.Add(new Slots { Name = "Class 1", Date = DateTime.Now.AddDays(1) });
slotsAvailable.Add(new Slots { Name = "Class 2", Date = DateTime.Now.AddDays(2) });
slotsAvailable.Add(new Slots { Name = "Class 3", Date = DateTime.Now.AddDays(3) });
slotsAvailable.Add(new Slots { Name = "Class 4", Date = DateTime.Now.AddDays(4) });
slotsAvailable.Add(new Slots { Name = "Class 5" });
slotsAvailable.Add(new Slots { Name = "Class 6" });
slotsAvailable.Add(new Slots { Name = "Class 7" });
slotsAvailable.Add(new Slots { Name = "Class 8" });
foreach (var items in slotsAvailable.GroupBy(m => m.Date).ToList())
{
foreach (var slotse in items)
{
Console.WriteLine("Date Value:" + slotse.Date.ToString());
}
}
}
public class Slots
{
public string Name {get;set;}
public DateTime Date {get;set;}
}
A quick and dirty fix for this would be to add a .Where to your .GroupBy that says Where Date != "1/1/0001".
foreach (var items in slotsAvailable.Where(m=>m.Date.ToShortDateString() != "1/1/0001").GroupBy(m => m.Date).ToList())
{
foreach (var slotse in items)
{
Console.WriteLine("Date Value:" + slotse.Date.ToString());
}
}