List the First Monday of every month using C# and VB.NET

Here’s some code for listing down the first Monday of every month in an year using C# and VB.NET. The Monday’s listed in this example are for the year 2010

C#

public static void Main(string[] args){    for (int mth = 1; mth <= 12; mth++)    {        DateTime dt = new DateTime(2010, mth, 1);        while (dt.DayOfWeek != DayOfWeek.Monday)        {            dt = dt.AddDays(1);        }        Console.WriteLine(dt.ToLongDateString());    }    Console.ReadLine();}

VB.NET

Public Shared Sub Main(ByVal args() As String)    For mth As Integer = 1 To 12        Dim dt As New DateTime(2010, mth, 1)        Do While dt.DayOfWeek <> DayOfWeek.Monday            dt = dt.AddDays(1)        Loop        Console.WriteLine(dt.ToLongDateString())    Next mth    Console.ReadLine()End Sub

OUTPUT

image

Share:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Twitthis
This entry was posted in C#, Syndicated, VB.NET. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree