I am working with an application written in C# which handles an agenda where every day can have some related information. For simplicity reasons, let’s define a Day object like the following:
public class Day
{
public DateTime date { get; set; }
public List<string> info { get; set; }
}
There’s a function that, given a starting date, will return a list containing all Days in the next week which have some information. Days in the next week that have info.Count = 0 are not in the returned list. Therefore, we can expect to obtain a List object with size 7 or less. Now, I have the following problem:
I want to show all seven days, whether or not they are on the obtained list.
The easy (and inefficient) solution I came up with is to code a function that takes the obtained List, reads it and adds the missing days (if any) into it. This way we always have a list with size 7 and can happily populate an asp:Repeater with it. But I think there is a better way to do this:
It is known in advance that the system has to display the next consecutive seven days starting from the given date. It shouldn’t be necessary to have the complete List to display the data. My question is, how can this be done? Am I going into the bad direction by doing this with a repeater?
I don’t see why adding the missing days is particularly inefficient. You’re talking milliseconds, if that. And it simplifies the rest of the code. Otherwise you’ll have to hand-code most of what a repeater does.
Sounds to me like you should go ahead and add the missing days to the list.