Click here to Skip to main content
14,458,710 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Programming Quiz Pin
Richard Deeming5-Nov-19 9:10
communityengineerRichard Deeming5-Nov-19 9:10 
GeneralRe: Programming Quiz Pin
W Balboos5-Nov-19 9:37
mveW Balboos5-Nov-19 9:37 
GeneralRe: Programming Quiz Pin
F Margueirat7-Nov-19 6:07
MemberF Margueirat7-Nov-19 6:07 
GeneralRe: Programming Quiz Pin
W Balboos8-Nov-19 4:08
mveW Balboos8-Nov-19 4:08 
GeneralRe: Programming Quiz Pin
Marc Clifton5-Nov-19 9:40
communityengineerMarc Clifton5-Nov-19 9:40 
GeneralRe: Programming Quiz Pin
Richard Deeming5-Nov-19 9:50
communityengineerRichard Deeming5-Nov-19 9:50 
GeneralRe: Programming Quiz Pin
Member 128503227-Nov-19 4:00
MemberMember 128503227-Nov-19 4:00 
GeneralRe: Programming Quiz Pin
AFell25-Nov-19 13:41
MemberAFell25-Nov-19 13:41 
Took this a step further and extended the code, and it should work with culture:
void Main()
{
    StringBuilder builder = new StringBuilder();
    
    Enumerable.Range(1, 12)
        .ToList()
        .ForEach(e => PopulateDayOfMonth(2021, e, builder));
        
    Console.WriteLine(builder.ToString().Trim());
}

static void PopulateDayOfMonth(int year, int month, StringBuilder builder)
{
    builder.AppendLine();
    int space = 6;
    int dashLine = 1 + (space * 7);
    
    IEnumerable<DateTime> days = Enumerable.Range(1, DateTime.DaysInMonth(year, month))
        .Select(d => new DateTime(year, month, d));

    builder.AppendLine(days.First().ToString("MMMMM"));
    builder.Append('-', dashLine);
    builder.AppendLine();
    builder.AppendLine($"|{string.Join("|", Enum.GetNames(typeof(DayOfWeek)).Select(d => $" {d.Substring(0, 3)} "))}|" );
    builder.Append('-', dashLine);
    builder.AppendLine();
    DayOfWeek dow = days.First().DayOfWeek;

    while (dow != 0)
    {
        builder.Append(' ', space);
        dow--;
    }

    bool first = true;
    
    foreach (var d in days)
    {
        if (!first && d.DayOfWeek == 0)
        {
            builder.AppendLine("|");
            builder.Append('-', dashLine);
            builder.AppendLine();
        }

        builder.Append($"|{d.Day.ToString().PadLeft(space - 2)} ");
        first = false;
    }

    builder.AppendLine("|");
    builder.Append('-', dashLine);
    builder.AppendLine();
}

With the following output:
January
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                              |   1 |   2 |
-------------------------------------------
|   3 |   4 |   5 |   6 |   7 |   8 |   9 |
-------------------------------------------
|  10 |  11 |  12 |  13 |  14 |  15 |  16 |
-------------------------------------------
|  17 |  18 |  19 |  20 |  21 |  22 |  23 |
-------------------------------------------
|  24 |  25 |  26 |  27 |  28 |  29 |  30 |
-------------------------------------------
|  31 |
-------------------------------------------

February
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
      |   1 |   2 |   3 |   4 |   5 |   6 |
-------------------------------------------
|   7 |   8 |   9 |  10 |  11 |  12 |  13 |
-------------------------------------------
|  14 |  15 |  16 |  17 |  18 |  19 |  20 |
-------------------------------------------
|  21 |  22 |  23 |  24 |  25 |  26 |  27 |
-------------------------------------------
|  28 |
-------------------------------------------

March
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
      |   1 |   2 |   3 |   4 |   5 |   6 |
-------------------------------------------
|   7 |   8 |   9 |  10 |  11 |  12 |  13 |
-------------------------------------------
|  14 |  15 |  16 |  17 |  18 |  19 |  20 |
-------------------------------------------
|  21 |  22 |  23 |  24 |  25 |  26 |  27 |
-------------------------------------------
|  28 |  29 |  30 |  31 |
-------------------------------------------

April
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                        |   1 |   2 |   3 |
-------------------------------------------
|   4 |   5 |   6 |   7 |   8 |   9 |  10 |
-------------------------------------------
|  11 |  12 |  13 |  14 |  15 |  16 |  17 |
-------------------------------------------
|  18 |  19 |  20 |  21 |  22 |  23 |  24 |
-------------------------------------------
|  25 |  26 |  27 |  28 |  29 |  30 |
-------------------------------------------

May
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                                    |   1 |
-------------------------------------------
|   2 |   3 |   4 |   5 |   6 |   7 |   8 |
-------------------------------------------
|   9 |  10 |  11 |  12 |  13 |  14 |  15 |
-------------------------------------------
|  16 |  17 |  18 |  19 |  20 |  21 |  22 |
-------------------------------------------
|  23 |  24 |  25 |  26 |  27 |  28 |  29 |
-------------------------------------------
|  30 |  31 |
-------------------------------------------

June
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
            |   1 |   2 |   3 |   4 |   5 |
-------------------------------------------
|   6 |   7 |   8 |   9 |  10 |  11 |  12 |
-------------------------------------------
|  13 |  14 |  15 |  16 |  17 |  18 |  19 |
-------------------------------------------
|  20 |  21 |  22 |  23 |  24 |  25 |  26 |
-------------------------------------------
|  27 |  28 |  29 |  30 |
-------------------------------------------

July
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                        |   1 |   2 |   3 |
-------------------------------------------
|   4 |   5 |   6 |   7 |   8 |   9 |  10 |
-------------------------------------------
|  11 |  12 |  13 |  14 |  15 |  16 |  17 |
-------------------------------------------
|  18 |  19 |  20 |  21 |  22 |  23 |  24 |
-------------------------------------------
|  25 |  26 |  27 |  28 |  29 |  30 |  31 |
-------------------------------------------

August
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
|   1 |   2 |   3 |   4 |   5 |   6 |   7 |
-------------------------------------------
|   8 |   9 |  10 |  11 |  12 |  13 |  14 |
-------------------------------------------
|  15 |  16 |  17 |  18 |  19 |  20 |  21 |
-------------------------------------------
|  22 |  23 |  24 |  25 |  26 |  27 |  28 |
-------------------------------------------
|  29 |  30 |  31 |
-------------------------------------------

September
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                  |   1 |   2 |   3 |   4 |
-------------------------------------------
|   5 |   6 |   7 |   8 |   9 |  10 |  11 |
-------------------------------------------
|  12 |  13 |  14 |  15 |  16 |  17 |  18 |
-------------------------------------------
|  19 |  20 |  21 |  22 |  23 |  24 |  25 |
-------------------------------------------
|  26 |  27 |  28 |  29 |  30 |
-------------------------------------------

October
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                              |   1 |   2 |
-------------------------------------------
|   3 |   4 |   5 |   6 |   7 |   8 |   9 |
-------------------------------------------
|  10 |  11 |  12 |  13 |  14 |  15 |  16 |
-------------------------------------------
|  17 |  18 |  19 |  20 |  21 |  22 |  23 |
-------------------------------------------
|  24 |  25 |  26 |  27 |  28 |  29 |  30 |
-------------------------------------------
|  31 |
-------------------------------------------

November
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
      |   1 |   2 |   3 |   4 |   5 |   6 |
-------------------------------------------
|   7 |   8 |   9 |  10 |  11 |  12 |  13 |
-------------------------------------------
|  14 |  15 |  16 |  17 |  18 |  19 |  20 |
-------------------------------------------
|  21 |  22 |  23 |  24 |  25 |  26 |  27 |
-------------------------------------------
|  28 |  29 |  30 |
-------------------------------------------

December
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
                  |   1 |   2 |   3 |   4 |
-------------------------------------------
|   5 |   6 |   7 |   8 |   9 |  10 |  11 |
-------------------------------------------
|  12 |  13 |  14 |  15 |  16 |  17 |  18 |
-------------------------------------------
|  19 |  20 |  21 |  22 |  23 |  24 |  25 |
-------------------------------------------
|  26 |  27 |  28 |  29 |  30 |  31 |
-------------------------------------------

GeneralRe: Programming Quiz Pin
BillWoodruff5-Nov-19 22:22
mveBillWoodruff5-Nov-19 22:22 
GeneralRe: Programming Quiz Pin
Richard Deeming6-Nov-19 8:20
communityengineerRichard Deeming6-Nov-19 8:20 
GeneralRe: Programming Quiz Pin
Member 110054785-Nov-19 22:20
MemberMember 110054785-Nov-19 22:20 
GeneralRe: Programming Quiz Pin
ZurdoDev6-Nov-19 2:02
mveZurdoDev6-Nov-19 2:02 
GeneralRe: Programming Quiz Pin
Jörgen Andersson6-Nov-19 3:04
communityengineerJörgen Andersson6-Nov-19 3:04 
GeneralRe: Programming Quiz Pin
ZurdoDev6-Nov-19 3:12
mveZurdoDev6-Nov-19 3:12 
GeneralRe: Programming Quiz Pin
Jane's Diary7-Nov-19 12:22
MemberJane's Diary7-Nov-19 12:22 
GeneralRe: Programming Quiz Pin
Fernando Takeshi Sato6-Nov-19 13:08
professionalFernando Takeshi Sato6-Nov-19 13:08 
GeneralRe: Programming Quiz Pin
PIEBALDconsult5-Nov-19 10:16
professionalPIEBALDconsult5-Nov-19 10:16 
GeneralRe: Programming Quiz Pin
EliaMelfior6-Nov-19 1:34
MemberEliaMelfior6-Nov-19 1:34 
GeneralRe: Programming Quiz Pin
Stuart Dootson6-Nov-19 2:50
professionalStuart Dootson6-Nov-19 2:50 
GeneralRe: Programming Quiz Pin
Jörgen Andersson6-Nov-19 3:01
communityengineerJörgen Andersson6-Nov-19 3:01 
GeneralRe: Programming Quiz Pin
Stuart Dootson6-Nov-19 3:39
professionalStuart Dootson6-Nov-19 3:39 
GeneralRe: Programming Quiz Pin
Jörgen Andersson6-Nov-19 4:04
communityengineerJörgen Andersson6-Nov-19 4:04 
GeneralRe: Programming Quiz Pin
agolddog6-Nov-19 3:39
Memberagolddog6-Nov-19 3:39 
GeneralRe: Programming Quiz Pin
StarNamer_3-Dec-19 6:42
professionalStarNamer_3-Dec-19 6:42 
JokeShe's a witch! Pin
honey the codewitch5-Nov-19 7:41
mvahoney the codewitch5-Nov-19 7:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.