Day of the week: Difference between revisions
Content added Content deleted
Line 337: | Line 337: | ||
{ |
{ |
||
DateTime date = new DateTime(i, 12, 25); |
DateTime date = new DateTime(i, 12, 25); |
||
if (date.DayOfWeek == DayOfWeek.Sunday) |
if (date.DayOfWeek == DayOfWeek.Sunday) |
||
{ |
{ |
||
Line 343: | Line 342: | ||
} |
} |
||
} |
} |
||
} |
} |
||
}</lang> |
}</lang> |
||
Using LINQ: |
Using LINQ: |
||
<lang csharp>using System; |
|||
using System.Linq; |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
string[] days = (from day in |
|||
(from year in Enumerable.Range(2008, 2121 - 2007) |
|||
select new DateTime(year, 12, 25)) |
|||
where day.DayOfWeek == DayOfWeek.Sunday |
|||
select day.ToString("dd MMM yyyy")).ToArray(); |
|||
foreach (string day in days) Console.WriteLine(day); |
|||
} |
|||
}</lang> |
|||
This looks better: |
|||
<lang csharp>using System; |
<lang csharp>using System; |
||
using System.Linq; |
using System.Linq; |
||
Line 382: | Line 360: | ||
foreach (string day in days) Console.WriteLine(day); |
foreach (string day in days) Console.WriteLine(day); |
||
} |
} |
||
}</lang> |
}</lang>Lambda expressions FTW: |
||
Lambda expressions FTW: |
|||
<lang csharp>using System; |
<lang csharp>using System; |
||
using System.Linq; |
using System.Linq; |
||
Line 399: | Line 374: | ||
} |
} |
||
}</lang> |
}</lang> |
||
{{out}} |
|||
<pre>25 Dec 2011 |
<pre style="height:20ex;overflow:scroll">25 Dec 2011 |
||
25 Dec 2016 |
25 Dec 2016 |
||
25 Dec 2022 |
25 Dec 2022 |