Announcing .NET 6 Release Candidate 2

Richard Lander

We are excited to release .NET 6 Release Candidate 2. It is the second of two “go live” release candidate releases that are supported in production. For the last couple months, the team has been focused exclusively on quality improvements. There are a lot of new features in the release, which only fully come together near the end. The team is currently validating end-to-end workflows to find the places where design intentions and technical reality don’t yet fully match. That’s led to teams tightening leaky pipes and paving paths all the way to their destination.

We’ve heard from users that upgrading production sites to .NET 6 RC1 has been both “boring” (non-event) and “exciting” (significant performance improvements). We’re confident that RC2 will continue that trend of having no surprises and exciting results.

You can download .NET 6 Release Candidate 2 for Linux, macOS, and Windows.

See the .NET MAUI and ASP.NET Core posts for more detail on what’s new for client and web application scenarios.

.NET Conf is a free, three-day, virtual developer event that celebrates the major releases of .NET. This year, .NET 6 will launch at .NET Conf November 9-11. We encourage you to save the date and tune in. Visual Studio 2022 Preview 5 is also releasing today and they have also announced that launch event happening on November 8. You can read all about that on the Visual Studio blog.

We’re at that fun part of the cycle where we support the new release in production. We genuinely encourage it. You can reach out to us at if you need guidance on how to approach that. A bunch of businesses have reached out and some are now in production. We also help Microsoft teams run on RC releases. Some Microsoft teams have gone into production on RC1 and we expect many more on RC2. This includes the .NET Website.

.NET 6 RC2 has been tested and is supported with Visual Studio 2022 Preview 5, also releasing today. .NET 6 will be supported with Visual Studio 2022 and not Visual Studio 2019. Similarly, it will be supported with MSBuild 17.x and not 16.x. If you want to use .NET 6, you will need to upgrade to Visual Studio 2022.

Visual Studio 2022 for Mac is currently NOT compatible with .NET 6 RC2. We are in the process of resolving that.

Check out the new conversations posts for in-depth engineer-to-engineer discussions on the latest .NET features.

The .NET 6 RC1 post was focused on foundational features, many of which will not see their full fruition until .NET 7. This post is focused on C# 10 and the related improvements to templates. It also includes an update on macOS and Windows Arm64 (which includes breaking changes). Let’s take a look.

C# 10

C# 10 is an important part of the .NET 6 release. For the most part, C# 10 is a further evolution of existing concepts and capabilities, like records and patterns. It also includes features — global using and file-scoped namespaces — that help you simplify your code and write less boilerplate. Those specific improvements are the basis of the template changes that are discussed later in this post. You can see the examples used in this section at .NET 6 examples. I’ll add more examples there for the final .NET 6 post.

Record structs

C# 10 adds support for record structs. This new feature is similar to C# 9 (class-based) records, with some key differences. For the most part, record structs have been added for completeness so that structs can enjoy the same record benefits as classes. However, the team did not simply structify records, but decided to align struct records with ValueTuple as much as class records. As a result of that design approach, record struct properties are mutable by default, while record class properties are immutable. However, you can declare a readonly record struct, which is immutable and matches the record class semantics.

At a high level, record structs do not replace record classes, nor do we encourage migration of record classes to record structs. The guidance for using classes vs structs applies equally to record classes and record structs. Put another way, the choice between classes and structs should be made before choosing to use records.

Let’s take a look at how record structs differ from record classes

This example of a record struct produces the following output.

Battery { Model = CR2032, TotalCapacityAmpHours = 0.235, RemainingCapacityPercentage = 100 }
Battery { Model = CR2032, TotalCapacityAmpHours = 0.235, RemainingCapacityPercentage = 0 }

As already stated, the most obvious difference is that record struct properties are mutable by default. That’s the key difference beyond being structs and the record struct syntax. I’ve also re-written the example with a readonly record struct, as follows.

You’ll see that it is almost identical to the (class) record example I published for C# 9.

Let’s review C# 9 records. They provide a terse syntax for defining struct-like data-oriented classes. They bias to immutability while offering a terse syntax — with expressions — for immutable-friendly copying. It might have surprised folks that we started with classes for a feature that is intended to be struct-like. Most of the time, developers use classes over structs, due to pass by reference as opposed to value semantics. Classes are the best choice in most cases and easier to use.

Struct records are very similar to class records:

  • They use the same syntax (with the exception of struct or class in the definition).
  • They enable customizing member definitions (new in C# 10) to use fields over (by default) property members.
  • They enable customizing the member behavior, using init or mutable properties.
  • They support with expressions. In fact, starting in C# 10, all struct types support with expressions.

Struct records differ from class records:

    • Record structs are defined with record struct or readonly record struct.
    • Record classes are defined with record or record class.
    • Record struct properties are mutable (get/set) by default.
    • Record class properties are immutable (get/init) by default.

The asymmetric (im)mutability behavior between record structs and record classes will likely be met with surprise and even distaste with some readers. I’ll try to explain the thinking behind the design. By virtue of pass by value semantics, structs don’t benefit from immutability nearly as much as classes. For example, if a struct is a key in a dictionary, that (copy of the struct) key is immutable and lookups will be performed via equality. At the same time, the design team saw that ValueTuple can be thought of as an anonymous record struct and that record structs can be seen as a grow-up from ValueTuple. That only works if record structs embrace mutability and support fields, which is exactly what the team decided to do. Also, embracing mutability is a reflection that structs and classes are different.

If you prefer the immutable behavior with record structs, you can have it by adding the readonly keyword.

Looking at structs generally, key functionality is common:

  • Equality checks are the same for all structs, provided by the runtime.
  • All structs can use with expressions for creating non-mutating copies, which is new in C# 10.

Global usings

global using enables you to specify a namespace that you would like available in all of your source files, as if it was declared in each one. It can also be used with using static and aliasing. This feature enables a common set of using declarations to be available, and by extension, for many using lines to no longer be needed. This is most relevant for the platform namespaces, but can be used for any namespace.

The following syntax can be used for the various using forms:

  • global using System;
  • global using static System.Console;
  • global using E = System.Environment;

These declarations just need to be declared once in your compilation to be effective throughout it. There are four patterns for declaring global using.

  • In Program.cs, make your root using statements global to the whole program by upgrading them to global using.
  • In a GlobalUsings.cs file (or some similar name), centrally manage all of your global using statements.
  • In your project file, with syntax that follows.
  • In your project file, enable the default platform using statements (for the MSBuild SDK your app relies on), with syntax that follows.

The following MSBuild syntax can be used in place of .cs files, in an <ItemGroup> (using analogs of the earlier examples).

  • <Using Include="System"/>
  • <Using Include="System.Console" Static="True"/>
  • <Using Include="System.Environment" Alias="E"/>

You can enable implicit using statements defined by the platform in a <PropertyGroup>.

  • <ImplicitUsings>enable</ImplicitUsings>

Implicit using differs by MSBuild SDK. Microsoft.NET.Sdk defines a basic set, and other SDKs define additional ones.

If you use the MSBuild capabilities, you can see the effective result in a generated file in the obj directory, as demonstrated by the following.

PS C:\Users\rich\app> type .\app.csproj | findstr Using
    <Using Include="System.Console" Static="True"/>
    <Using Include="System.Environment" Alias="E"/>
PS C:\Users\rich\app> type .\obj\Debug\net6.0\app.GlobalUsings.g.cs
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using E = global::System.Environment;
global using static global::System.Console;

You can see that the Microsoft.NET.Sdk adds several global using statements, in the .GlobalUsings.g.cs file. Note that the global:: operator isn’t necessary and can be safely ignored in terms of developing an understanding of the generated syntax.

File-scoped namespace declaration

File-scoped namespace declarations is another C# 10 feature that is aimed at reducing indentation and line count.

The syntax for this feature follows:

namespace Foo;

It is an alternative to the traditional three-line syntax:

namespace Foo

The three-line syntax can be nested. The one-line syntax does not support nesting. There can only be one file-scoped declaration per file. It must precede all types defined in the file, much like the three-line syntax.

Namespaces are not compatible with top-level statements. Top-level statements exist within the top-level namespace. This also means that if you add additional methods to the Program class, using the partial class syntax that the partial Program class needs to also be in the top-level namespace.

This feature is very similar to the one-line using declaration that was added to C# 8.

const and interpolated strings

Interpolated strings can now be assigned to const variables. Interpolated strings are intuitive to use and read, and should be usable everywhere. They can now be used with const provided that the placeholder values are also constant.

The following example demonstrates a possible use case:

Many other improvements have been made to interpolated strings, which are described in String Interpolation in C# 10 and .NET 6.

Extended property patterns

You can now reference nested properties or fields within a property pattern. For example, the following pattern is now legal:

{ Prop1.Prop2: pattern }

Previously, you’d need to use a more verbose form:

{ Prop1: { Prop2: pattern } }

You can see this more compact form used in the following example, for example with Reading.PM25.

.NET SDK: C# project templates modernized

We modernized .NET SDK templates with Preview 7, using the latest C# features and patterns. There was significant feedback on those changes, in part because builds started to fail. As part of the initial templates update, we enabled implicit usings by default (AKA opt-out) for .NET 6 (net6.0) projects (including if you updated an app from .NET 5 to .NET 6). That has been changed. We’ve updated the SDK so that all the new features are opt-in. The response to that change (which was made in RC1) has been positive.

There was also feedback that some folks didn’t like the new simplified Program.cs file, with top level statements. We’ve made improvements to top-level statements in response and continued to use it for templates. We expect that most developers who prefer the traditional approach can straightforwardly add the extra ceremony themselves.

The following language features are used in the new templates:

  • async Main
  • Top-level statements
  • Target-typed new expressions
  • Global using directives
  • File-scoped namespaces
  • Nullable reference types

We built all of these features because we think that they are better than the previous alternative. Templates are the easiest and best way to steer new developers and new apps to use the best patterns. The C# design team is a big believer in enabling the use of fewer lines, fewer characters to specify a given concept or operation, and the reducing needless repetition. That’s what most of these new features enable. Nullable differs in that it results in more reliable code. Every app or library that uses nullable is less likely to crash in production. Software is too complicated for human minds to see the mistakes that a compiler can.

A common theme across these features is that they reduce noise and increase signal when you are looking at your code in a code editor. More important aspects should now pop. For example, if you see a using statement in a given file, it’s a special one needed beyond the implicit set. You should be able to copy/paste code from one file to another without needing to CTRL-. types to add the required namespaces (at least not as much). If you see nullable warnings or errors, you know that your code is likely incorrect in some way. There is also the benefit of removing indentation. More of your code will be visible within the first dozen columns of your editor, as opposed to those columns being filled with just space characters. One can think of these features as delivering higher density of specificity and meaning to your eyes, on the way to your brain.

Console template

Let’s start with the console template. It’s very small.


// See for more information
Console.WriteLine("Hello, World!");

Project file:

<Project Sdk="Microsoft.NET.Sdk">



Even though the console template is much more minimal that its .NET 5 counterpart, there is no reduction in functionality. You can also see that ImplicitUsings is now an opt-in feature, and is enabled in the templates.

Web templates

The web template is similarly minimal.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");


The webapi template maps more closely to typical ASP.NET Core apps. You will quickly notice that the split between Program.cs and Startup.cs has been removed. Startup.cs is no longer required.


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

// Learn more about configuring Swagger/OpenAPI at

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())





The project file for the webapi template is similar to the console one.

<Project Sdk="Microsoft.NET.Sdk.Web">


    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />


You can see that file-scope namespaces are used throughput this sample, including in WeatherForecast.cs:

namespace webapi;

public class WeatherForecast
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    public string? Summary { get; set; }

Target-type new is used with WeatherForecastController.cs:

private static readonly string[] Summaries = new[]
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"

In the mvc template, you can see the use of nullable annotations and an expression-bodied method.

namespace webmvc.Models;

public class ErrorViewModel
    public string? RequestId { get; set; }

    public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

Windows Forms templates

The Windows Forms template has also been updated. It includes most of the other improvements covered with the other templates, although notably not top-level statements.

namespace winforms;

static class Program
    /// <summary>
    ///  The main entry point for the application.
    /// </summary>
    static void Main()
        Application.Run(new Form1());

You can see the use of the one-line namespace statement and the lack of any platform-level using statements due to enabling implicit usings.

WPF templates have not been updated as part of the release.

Implicit usings

I’ll now show you these features in action. Let’s start with implicit usings. When enabled, each Sdk adds its own set of implicit using statements.

As demonstrated earlier, the Microsoft.NET.Sdk adds several global using statements.

If this feature is disabled, you’ll see that the app no longer compiles since the System namespace (in this example) is no longer declared.

PS C:Usersrichapp> type .app.csproj | findstr Implicit
PS C:Usersrichapp> dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21501-01+bbcce1dff for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See:
C:UsersrichappProgram.cs(2,1): error CS0103: The name 'Console' does not exist in the current context [C:Usersrichappapp.csproj]


Another option is to use the global using feature, which enables you to only use the namespaces you want, as you can see in the following example.

<Project Sdk="Microsoft.NET.Sdk">


    <Using Include="System" />


Now, building the code.

PS C:Usersrichapp> type .app.csproj | findstr Using
  <Using Include="System" />
PS C:Usersrichapp> dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21501-01+bbcce1dff for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See:
  app -> C:UsersrichappbinDebugnet6.0app.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.80

That’s not the recommended general pattern, but is a good option for folks that want maximum control. In most cases, we expect that developers will rely on the implicit usings provided by the SDK and take advantage of explicit global usings for namespaces from their own code or NuGet packages that they use pervasively.


I’ve updated Program.cs to demonstrate nullable reference types. The app calls a List<T> method that returns a T?, in this case a nullable string (string?).

List<string> greetings = new()
    "Nice day, eh?"

string? hello = greetings.Find(x => x.EndsWith("!"));
string greeting = hello ?? "Hello world!";

Console.WriteLine($"There are {greeting.Length} characters in "{greeting}"");

The line that defines the hello variable won’t compile without being defined as var, string? or addressing the case where List<T>.Find returns null. Without the nullable feature enabled, I might miss this problem, which would result in my code crashing with a NullReferenceException exception. That’s no good. I’m handling that on the next line with ??, the null coalescing operator. In most cases, these two lines would be merged into one, as you can see in the following code. I’ve kept them separate (in this contrived example) so that you can see my use of string? to accommodate an API that returns a nullable reference type.

string greeting = greetings.Find(x => x.EndsWith("!")) ?? "Hello world!";

In this example, I’ve merged everything into one line. I can now declare the variable as string since the null-ness has been accommodated with the string that follows ??. The string? in this case is something that only the compiler sees.

string[] args

I’m now going to quickly address the questions that most people ask about top-level statements, including the args parameter. The args parameter remains available with top-level statements. It’s just less obvious. Here’s another program that demonstrates using it.

string greeting = args.Length > 0 ? string.Join(" ", args) : "Hello World!";
WriteLine($"There are {greeting.Length} characters in "{greeting}" in this {nameof(Program)}.");

It produces the following output.

PS C:\Users\rich\app> dotnet run
There are 12 characters in "Hello World!" in this Program.
PS C:\Users\rich\app> dotnet run Nice day, eh?
There are 13 characters in "Nice day, eh?" in this Program.

This app also demonstrates that the Program type is still defined. Program.Main is not.

I removed the Console from Console.WriteLine in Program.cs by adding a global static using to my project file, as follows.

<Project Sdk="Microsoft.NET.Sdk">


    <Using Include="System.Console" Static="True"/>


Defining regular methods

We’ve heard the feedback from some folks that real methods are preferred over local functions, specifically for the Program class. You can use either model with top-level statements.

I’ve kept the program the same, but switched all the functionality to static method in the Program class, defined in a partial class.




public partial class Program
    public static string GetTheGreeting(string[] args)
        string greeting = args.Length > 0 ? string.Join(" ", args) : "Hello World!";
        return $"There are {greeting.Length} characters in "{greeting}" in this {nameof(Program)}.";

It produces the same result as the previous example. The Program.Foo.cs filename is arbitrary. In fact, so is Program.cs. You can name these files whatever you’d like. The compiler will figure it out.

As mentioned earlier, the Program type must be in the top-level namespace when using top-level statements.

macOS and Windows Arm64 Update

We have good news, but also some breaking change to share. The project to support macOS and Windows arm64 is almost done. We’ve been working on it for over a year, with help when we needed it from the fine folks on the macOS and Windows teams. At first, we thought that the project was solely about supporting Arm64 on macOS and that Rosetta 2 would cover x64. Easy and just about ISAs, right? Not quite. As we dug deeper, it became clear that x64 + Arm64 co-existence was the bigger task to take on, focused on the CLI and installers, including a few places where they need to agree. With RC2, we’re delivering builds of .NET that we deliver the best experience we could imagine.

I’ll provide a quick summary of where we are at for macOS and Windows Arm64 machines:

  • .NET 6 RC2 enables Arm64 + x64 co-existence by installing Arm64 and x64 builds to different locations. Until now, Arm64 and x64 builds overwrite each other, which led to general sadness.
  • You need to uninstall all .NET builds and start from scratch (on macOS and Windows Arm64 machines) to adopt .NET 6 RC2+. This includes Arm64 and x64, .NET 6 and pre-.NET 6.
  • Pre .NET 6 builds are not yet ready to install.
  • The CLI enables you to use the Arm64 SDK to do Arm64 AND x64 development (assuming you have the required Arm64 and x64 runtimes installed). The same is true in reverse.
  • We want people to just use the Arm64 SDK since it will be a better experience (native architecture performance; one SDK to maintain). We will continue to improve the product to make this model the easy choice for most developers.
  • For the SDK, we will only support .NET 6+ on Arm64. Earlier SDK builds will be blocked on Arm64.
  • For runtimes, we will support all in-support versions, Arm64 and x64.
  • .NET 6 RC2 delivers the bulk of the final .NET 6 experience for Arm64 (including x64 emulation).
  • We hope to update .NET Core 3.1 and .NET 5 runtimes to align with .NET 6 RTM (both in time and with the technical requirements). That’s still TBD.
  • RC2 nightly builds are currently broken, so you will need to wait a couple more weeks until we actually ship RC2 to try this all out.
  • The .NET 5 SDK for Windows Arm64 will go out of support early, with .NET 6 RTM.

We’re also considering making breaking changes to dotnet test to unify the arguments we use for architecture targeting:

A big part of the project is enabling the use of x64 runtimes with the Arm64 SDK. You can see that demonstrated in the following image.

x64 on Arm64, Announcing .NET 6 Release Candidate 2

If you want more details, check out dotnet/sdk #21686.

Contributor showcase

In developing .NET 6, we appreciate the many contributions of our GitHub community. As we did in our Preview 7 and RC1 posts, we’d like to recognize just a few of those.

This text is written in the contributors’ own words:

Alexandr Golikov (@kirsan31)

My name is Alexandr Golikov and I am from Saint Petersburg, Russia.

I have been writing stock trading software for over 15 years, mostly with .Net Framework and WinForms. As soon as .Net Core WinForms became open source and a preview version was released, I started trying to migrate our projects into it and contribute to solving both old problems that were in .Net Framework and new ones. At this moment all of our projects are working on .Net 5.0. But .Net 6 is already almost here, and .Net 7 is on the horizon, and… I hope that I will continue to contribute to this great framework, and will have more free time for this 🙂

In the end, I want to thank the whole .Net team and especially the WinForms project developers and maintainers!

Tobias Käs (@weltkante)

I’m Tobias Käs and mostly visible under the alias weltkante on github. I’m from Germany, studied computer science in Frankfurt and am currently living in Mönchengladbach. I’m coming from a low level C++ programming background but have switched to C# programming as my main language ever since it distinguished itself from Java by adding generics in .NET 2.0.

I’ve been working over 12 years programming desktop applications in .NET Framework using WinForms and later WPF. I have spent a lot of time digging into the internals of .NET and its UI frameworks to learn how they work, debugging issues, finding workarounds, and in general getting the most out of these frameworks. Ever since they went open source I’m trying to give back from what I learned, following issue discussions, commenting pull requests, or doing the occasional contribution.

Ivan Zlatanov (@zlatanov)

My name is Ivan Zlatanov, and I am from Botevgrad, Bulgaria. I dipped my toes in the world of software first in high school where we did competitive programming in Turbo Pascal. I’ve spent the next summer doing some PHP and learning about the web dev. Not long after an opportunity arose where I could learn C# and ASP.NET 2.0 and once I picked that, I never stopped. I’ve been programming with C# and .NET for almost 14 years now.

I love contributing to open-source projects because I can help others. I love the immediate feedback you get from reviews and the open discussion of problems and solutions with other people around the globe. As Scott Hanselman once said that we only have limited keystrokes left in each of us, so we better spend them well.

Contributing to Open Source and in particular .NET is keystrokes spent well.


C# 10 offers significant improvements in simplicity and expressiveness, building on similar features in C# 9. In the past, one could reasonably poke fun at C# for requiring so much ceremony and knowledge of object oriented concepts just to write a single line of code. Those days are behind us, and the templates reflect that. Part of the motivation for these changes has been to make C# more attractive to new programmers and schools. These simplifying changes fundamentally change what you need to learn to get started with and become skilled using C#. In its new default form, it is directly comparable to other languages that similarly start with a single file source file.

We look forward to seeing other projects simplify their new user experiences with top-level statements, global using, records and many of the other modern features. There is a lot of opportunity to create simpler learning journeys for both open source projects and commercial offerings.

We encourage you to use .NET 6 RC2. We’re confident that you’ll find it a solid release. And save the date for .NET Conf on November 9 for the .NET 6 launch.

Thanks for being a .NET developer.


Comments are closed. Login to edit/delete your existing comments

  • AlseinX 0

    I wonder where the package System.Runtime.Experimental goes to.
    The package is published on to opt-in generic maths.
    But I didn’t see any new version since RC1 was released, and the package is missing again with RC2.
    Is it moved to any other nuget package or framework reference? Or is there a new undocumented way to opt-in the related APIs?

  • Lucian Bargaoanu 0

    Perhaps I’m being silly, but namespace webapi; means namespace MyWebApiApp;? Because I thought it might be an alias defined somewhere 🙂

    • Gábor Szabó 0

      I’m sure not. That declaration means the root user namespace for the Web API project was named “webapi” instead of something with a conforming public namespace name, like “WebApi”. It’s what you get when you create a new app with "dotnet new webapi" in a folder called “webapi”.

      • Richard LanderMicrosoft employee 0

        Right. It just means what it says. The namespace for that file is webapi. There is no magic or translation.

  • Esben Sundgaard 0

    I love the new templates. It’s great that we now have a much cleaner program with much less ceremony.

    • Someone 0

      What is cleaner? That you don’t know what is args variable?

  • Gábor Szabó 0

    I wasn’t considering leaving a comment but reading the ones already here changed my mind. I’d like the teams to know that there are many of us agreeing with many if not all decisions made and are very happy with how the C# language and .NET is evolving. Some unhappy opinions may sound louder, but there are plenty of people still being very happy, they just mostly stay quiet.

    About C#: I, for one, am very happy to see global usings, top level statements, and simplified namespace declaration. I’m indifferent about implicit usings, and understand why args is made ambient in top-level statements. What I don’t understand is why people get “upset” when all of these features you can “ignore”. I say with 100% confidence that these changes ALL make learning C# better for newcomers, and in no way they make it harder.

    I’ve been teaching C# and .NET for 7 years now at university. I’m happy that now I can skip teaching most of the ceremony regarding ASP.NET Core’s Startup and Program classes. Why do people think that it’s easier for a programming beginner to understand what a Main method is instead of a top-level statement?

    I try to be as precise in my articulation of my views as possible. But people getting “upset” about new features they are free to ignore (and live in the past) makes me upset in turn. Why do people think args is “magic” and Main(), [STAThread], nameof are not? Why do they think it’s easier for a newcomer to understand how OO works and how to write OO code at all than just writing the program itself that should be written? Most of the ceremony is itself “magic” anyways, until you need to take a peek under the hood. How would knowing all of these ceremony help one that starts out writing their first program? You can write one line of JavaScript and it WILL WORK in the browser.

    I think the design philosophy of both .NET and C# follows that there should be good, concise and beginner-friendly defaults, and there should also be a way to configure behavior for advanced scenarios. If you don’t agree with these, or think any change goes against these, I’d rather you point out how it conflicts with the philosophy or how the philosophy itself doesn’t benefit you (or anyone), than just waving your opinions about like they are universally accepted facts.

    • Someone 0

      I understant what you and Mr Richard say, but I think top-level statements, magic args, implicit Program class and Main method don’t make it better to beginners. Btw, who are all these beginners? CS students who already got basic programming skills by learning C/C++? People like these understand Main method and it’s ok. People who want to learn OOP have to learn OOP, so C# is great for that. You can define Program class with Main method and it’s ok. It works and it’s easy to understand.

      Kotlin or Rust also uses explicitly Main function and it doesn’t feel bad. Java is OOP language and beginners learn it and everything is fine too.

      • Gábor Szabó 0

        The best way I can put it is this: let’s just agree to disagree. I taught many people who had previous experience with other OOP languages (mainly C++ and Java), and people who never saw a line of code before in their lives, just to answer your question. The latter has a hard time grasping what even a class is, but usually they understand what objects are right away. So no, it is not “ok” to have a Program class and a Main method just for the sake of it. Making minimal APIs can lower the entry barrier by a lot for beginners and amateurs.

        I never saw such cargo cult worship before for Program.Main, didn’t know you guys existed before. Where were you when ASP.NET had Global.asax and there was literally no entry point? Or why didn’t you sing your praises when ASP.NET Core reintroduced not having a magic entry point?

        Why does nobody want to go back to when the Main method needed to have an int return value? Because the return 0; at the end is just as much unneeded boilerplate as the rest of the file is, that’s why.

        Are you trying to convince people that “top-level statements are bad” or something? What’s in it for you? You left like 10 comments on this post already.

        • Someone 0

          I will answer because I hope somebody understand my point of view. Keep in mind that I’m not expert, professional programmer or beginner.

          I started learning C# in 2021. I wrote long comment in previous blog post which was published approximately 2 or 3 months ago. I really like C# has fairly clean and easy syntax (compared to Rust, Python, JavaScript, Java, C++) and webapi ASP.NET Core and console templates are easy to follow and understand. There’s Program.cs, Startup.cs, controllers, entities, you can create DTOs and so on. Everything seems to be well done. I enjoy learning because I finally understood general programming concepts such as DTOs, AutoMapper and somehow Dependency Injection. I know I’m poor programmer but I understood some concepts thanks to C#. Also C# uses OOP, so it isn’t like Python or JavaScript where you can write procedural code, because C# heavily uses classes. Easy to understand, easy to follow and there isn’t mess as in Python or JavaScript. I don’t like Python or JavaScript because you don’t know where to start – just empty file with any help and also they’re different languages, not strong typed like C# is.

          You asked me about top-level statements feature and default templates etc. I don’t like it for few reasons:

          1. It makes too much implicit code. You have to find out on other source that these top-level statements are transformed into auto-generated Program class and Main method. Finally, you have to define a class and a method anyway, because C# is designed to use them. So, why do Mr. Richard and dotnet designers want to hide these programming elements? The mythical beginner will have to get to know these concepts sooner or later.

          2. It makes Program.cs looks weird compared to all other *.cs files in all projects. We have a file which doesn’t contain any class, because it’s hidden by default, so beginners or people who like clean code or people have a neurosis of perfection will struggle because after generating new project (dotnet new command) they have to type “boilerplate” stuff on their own. I understand about that top-level statements can be used for writing one-file scripts or files for learning purposes. That’s could be fine, but why do we need it to being default enabled? Why do we need to hide obvious parts of C# projects? If somebody want to learn C, C++, Rust, Kotlin, Java or any other language which contains explicitly set entry point that’s fine and easy to understand. Since 2002 when C# came out everything was fine too. C# hello world has explicitly defined Program class, Main method and it works out of the box.

          3. I don’t like too much implicit stuff in code. Why? It makes harder to understand what is going on. Also it forces you to remember what is default value of something. For example, class can be created with public or internal access modifier. Ok, that’s nice and we also have default access modifier which in this case is internal. But in C# programs we don’t have to write explicitly access modifiers because we can use default ones. Yes, it’s very helpful and I like it because we don’t have to type so much, but there’s problem.

          Imagine 2 people who work on code. Here’s the code.

          class User
              string Name { get; set; }

          First person uses default values and implicit stuff all over again. Second, less experienced person doesn’t use implicit stuff so he/she doesn’t remember what is default value. In this context, second person has to search documentation what is default stuff in C# or try to remember that internal is default access modifier for class definition. Instead of remembering that kind of stuff (and there’s so many places with default stuff), first person could write explicit access modifier instead of hiding it.

          namespace MyConsoleApp.Models;
          internal class User
              public string Name { get; set; }

          And that’s it. If something is explicitly written then I, Gábor Szabó, Mr. Richard or this second person from my story could read code and then know what is going on. Ok, he/she reads code and sees that’s class was definied with internal access modifier, so the class could be accesed only inside one assembly. Final code is more verbose, but it’s clean, easy to read and understand. We don’t have to guess or search in Google what is default access modifier and what is behind on the scenes. But that’s simple example and I know it might be not so good to explain what I’m thinking now.

          Remember that nobody wants to get bad for .NET. I’m really happy that C# evolving but on the other hand I don’t want to see weird changes in syntax and features. Sometimes it’s better to introduce release with stability/performance improvements, fixed bugs than forcibly introduce so many new features so that it doesn’t turn out that language doesn’t develop. As professionals, you should know better LESS but more QUALITY. Keep things simple, not over engineered, don’t get hyped by some communities, JavaScript or Rust. If you want to have better JavaScript then focus on your TypeScript. If somebody asks me if Rust is great choice for beginners or if it has clean syntax I will say: no, Rust isn’t good for beginners and Rust doesn’t have clean syntax. If somebody asks me if C# is great choice for beginners or if it has clean syntax I’d like to say: yes, C# is amazing for beginners and C# has clean syntax without weird stuff and too many complicated and not needed features.

          That’s my answer. If somebody wants to ask me something, feel free to ask. If somebody wants to say something, feel free to do it. Maybe I don’t understand something, so you could help me a little 🙂

          • Marina Reva 0

            I agree at all.

    • Andrew Buchanan 0

      I completely agree and was going to write about the same thing.

    • Mohan Murali 0

      Yes, the new changes look awesome. I am also not someone who usually comments, but I feel I need the team to know that they are doing great job and we are very happy with the changes. Cant wait to try these and see how much loc i can reduce.

  • Someone 0

    I tested .NET 6 preview and fortunately adding Program class and Main method is easy. It is cleaner, at least for now.

    namespace MyService;
    public class Program
        public static void Main(string[] args)
            var builder = WebApplication.CreateBuilder(args);
            // Add services to the container.
            var app = builder.Build();
            // Configure the HTTP request pipeline.
    • Marco Borm 0

      I agree that these templates are really bad in terms of having a good starting point for a really useful application. They are good as a starting point for a hello world and then throw it away.
      But even if I am wrong and also others that do not like the super minimized templates: Why not offering something that allows you to get the code a bit extended if choosing the same template? Just a checkbox…

      • Someone 0

        @Marco Borm: You’re right. After all, this class is generated by the compiler anyway, why should it be hidden by default? Because beginner or “wannabe programmer” won’t be able to understand what class is? Does he/she have to know what class is at the beginning? I think he/she doesn’t have to, and since 2002 (or maybe even earlier) nobody has made a problem out of it. It should be made clear that C# programs need Program class and Main method, because it is used behind the scenes, so what is the point of hidding them for people? You want to learn C# programming then learn it.

        Mr. Richard wrote about various models, such as the C model, Rust, Swift, Kotlin. What’s wrong with the C model? After all, C# has C in its name. Why in the case of Rust you can have an explicit main function, and in the case of C# it becomes a problem? Because you want to change C# to JavaScript or Python? Why? They’re different languages. There’s also TypeScript so people don’t need another language like that.

        Clean, easy to understand syntax and rules, not mess, not too complicated and over engineered “features” and syntax changes – people want to language which is easy to use. Even Rust isn’t clean compared to other solutions. If you want to talk about Rust then I’ll say that it is over complicated in many cases. C# beats Rust in so many syntax scenarios, at least for now. It’s easier to read C# than Rust.

        Hello Worlds


        #include <stdio.h>
        int main()
           printf("Hello, World!");
           return 0;


        fun main(args : Array) {
            println("Hello, World!")


        fn main() {
            println!("Hello World!");


        package world;
        public class HelloWorld {
            public static void main(String[] args) {
                System.out.println("Hello World");

        and my wannabe C# easy to follow hello world. Ok, we can hide common “using System;” if needed but I don’t see the point. Just write classes which don’t require a lot of usings. Keep everything simple, clean and readable.

        using System;
        namespace Tutorial;
        class Program
            static void Main(string[] args)
                Console.WriteLine("Hello World!");


      • Alexander Batishchev 0

        +1. Please allow users to choose.
        Right now the decision is made based on the taste of someone at Microsoft. Let users decide for themselves.

  • Aaron Layton 0

    Does anyone know how you add Summary and Remarks to an app.MapGet with the new minimal Api?

  • J KmB 0

    Dear Richard, by mentioning WinForms it crossed my mind – would there be some kind of updated tutorial and tools for a NET4.7-> NET6 migration of WinForms applications?

  • Andrew Buchanan 0

    I’m most looking forward to the namespace change and the global usings. One less set of meaningless indentation means I get back some screen real estate for actual text/code/toolbars etc in every file and shaving a bunch of usings off the top of each file feels cleaner as well.

    The lazier list initializations and string interpolation stuff will occasionally save some effort as well but I suspect it’s a once a day type thing.

  • Midnight 0

    I’m happy because completed to learn C# basics with the old templates. Now it’s a lot of implicit stuff and it’s really hard to undersrand how it really works. But now for me it doesn’t matter. It’s likely as hard to understand how async/await works. No way to write a proper (production) code without deep diving to async code nature. I guess top-levels + implicits will give the similar effect starting from the first stack trace inspection. What is Program? Where’s it?

    AFM, implicit usings must be definetly disabled. I prefer more control. Thanks for the option.

    Looking forward for Windows App SDK posts.

    • Richard LanderMicrosoft employee 0

      You can write async code with top-level statements. Just write the code. It will work.

      • Midnight 0

        Thanks. I’m aware but that’s not what I meant. Sorry for my probably bad English.

        I meant that top-level-implicit-usings-code is really easier to write for beginner even without of OOP awareness. Like async/await easy to write without multithreading awareness. But it’s hard to understand how it really works.

        You were instroduced another “magic” in C#. Do you know why a lot of devs literally hate JavaScript? Because it’s language of “magic”. Like “everything works (or doesn’t work) but no one knows why/how”.

        If there no Program.Main anymore by default then I prefer no Main on IL level for the case. I don’t want to see Main in Stack Trace. I like when it works as it looks.

        That what I meant.

    • anonymous 0

      this comment has been deleted.

  • Kirsan 0

    Totally agree that top-level is something terrible.
    It’s not easy for beginners, it will confuse them.

Feedback usabilla icon