I have gallery in my project and I want to group it by their upload date for example if page = 1 it should show 2019/1/2 pictures and if page = 2 it should show 2019/1/4 pictures but I can't do it. It says I can't select Dates[Page - 1]
.
public IEnumerable<GalleryPictures> GetGalleryByDates(int Page)
{
var AllGalleryPictures = GetAllGalleryPictures();
var Dates = AllGalleryPictures.Select(p => p.UploadDate).ToList().Distinct().OrderByDescending(p=>p);
return AllGalleryPictures.Where(p => p.UploadDate == Dates[Page - 1]);
}