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
Select C# console app from the list and click on next
Configure your project like name and location
Select the target framework .Net 6.0 and click on create
The project structure looks like below.
Here we will get the following
- No namespaces.
- No Main method.
- No Program class.
- No using statements.
The created console application project .csproj file
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
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.
The Project .csproj file
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
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.