.NET 6 New feature Of Console Application

Starting with .Net 6, we will create a new console application with target framework .net 6.

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

 .Net 5 or lower version of the framework.

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

The above two programs' output will be the same, both programs represent the same. When you use a newer version, you only need to write logic code, you don't need to include other program elements. like Main Method, Namespaces, and Program class.

Follow the below steps, create a project and we will check the output. 

Select create a new project option 

.NET 6 New feature of Console Application

Select C# console app from the list and click on next

.NET 6 New feature of Console Application

Configure your project like name and location 

.NET 6 New feature of Console Application

Select the target framework .Net 6.0 and click on create 

.NET 6 New feature of Console Application

The project structure looks like below.

Here we will get the following 

  • No namespaces.
  • No Main method.
  • No Program class.
  • No using statements.

.NET 6 New feature of Console Application

The created console application project .csproj file 

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
</PropertyGroup>

.NET 6 New feature of Console Application

If we create console applications in the .Net 5 or lower version of frameworks we will get the namespaces, program class, Main method, and using statements like below.

.NET 6 New feature of Console Application

The Project .csproj file 

.NET 6 New feature of Console Application

If we want to get all the namespace, main method, program class, and using statements, create project using .net5 target framework and edit the project file (.csproj file) change the target framework net5.0 to net6.0

Output

.NET 6 New feature of Console Application

Conclusion

The output of the two programs is the same. In .net 6 we will not get namespaces and main methods etc.. only we will get logic statements.