C# Console app template changes

I've spent a lot of my time teaching C#. And the starting point for my students was always an empty console application. Something like this:

using System;

namespace OldSchoolConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

This is what you used to get when you created an empty console application in Visual Studio. It brings in the System namespace so that you can interact with the user and then creates a namespace and a class containing the Main method that makes everything happen. (in this case print "Hello World!")

However, if you use Visual Studio 2022 and .NET 6.0 to create an empty console application you will get this:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

The link in the code gets you to a description of what has been done and the C# features that make it possible. I can understand the reasons for the change. You can run a Python or JavaScript program from a single statement and so someone must have thought that C# needed that feature too. However, I'm not convinced that the change is a good one.

I really liked the way that the old arrangement forced the reader to consider the way C# programs are structured and managed. My C# Yellow Book makes a big feature of going through all the statements in a complete program right at the start, so readers appreciate how C# programs fit together. The new single line arrangement might give the impression that I'm doing stuff that is unnecessary and making things complicated when I'm really paving the way for understanding of how everything works. The new design doesn't really make it easier to construct programs. If you want to use classes in your simple one-line program it all falls apart with build errors that make little sense to the beginner.

The good news is that you can just delete the one line solution and go back to the old program if you want to. Which is what I plan to tell people to do.

Update

I’ve just decided I’m wrong here. If I think about the issue properly (something that only ever seems to happen after I’ve posted an article) I reckon that the new console format is a good idea, especially from the point of view of teaching programming. When I wrote Begin to Code with C# I invented a framework (called Snaps) that makes it trivially easy to create a universal windows application with a minimum of surrounding code. This change is doing exactly the same thing for console apps.

My argument above doesn’t point up a flaw in the new design, it points up a desire on my part to keep my teaching sequence the same, rather than look at simplifying the learning process.

I’m now going to re-write the first part of the C# Yellow Book to make use of this new feature and make it easier to focus on what programs do before moving into the features that make solutions easier to manage. My apologies to the .NET 6 team, you’ve actually done something really nice.