No matter what version of framework you are using, the following will always work:
using System;
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
However, with newer versions of framework and SDK, the following works for .NET 6+:
Console.WriteLine("Hello, World!");
Above is a complete console app, when the top-level statements are enabled in project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Learn more about new project template
To learn more about the new template, take a look at the following article
Which explains new features like:
- Implicit
using
directive - Global
using
directives
Choose between old and new project template
When you create a new .NET (not .NET Framework) console application, you can choose between the old style or new style:
Tutorial - Create a .NET console application using Visual Studio
You can learn more about console applications in the following articles: