I am really getting into LINQ now! I think it’s fantastic. I recently wanted to develop a quick drop-down list in ASP.Net which allows a user to select a time of day from a list. The times are 15 minutes apart, so the list would look like this:


08:00
08:15
08:30
08:45
09:00

… and so on.

Before LINQ, I would have done this with a for loop, like this:

List<string> times = new List<string>();
for (int hour = 0; hour < 24; hour++)
  for (int minute = 0; minute < 60; minute++)
    if (minute % 15 == 0)
       times.Add(string.Format(
         "{0:00}:{1:00}", hour, minute));

That’s not difficult, although it’s not so easy to understand. I would have to write a small console app or test to make sure I had done it correct though.

I thought this might be a good opportunity to use LinqPad. It’s a great tool. You can use it to test a LINQ statement in a live window, so I thought I’d give it a go.

First I needed a LINQ statement to test.

More >