Understanding top-level statements
With C# 9.0, the language team focused on removing redundant code to be written by the developer. One such feature to do so is top-level statements. This feature enables the developer to remove the ceremony code in the main entry point of the application.
If we create a console application in Visual Studio, the content we see in Program.cs is as shown in the following code snippet:
using System;
namespace TopLevelStatements
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World!”);
}
}
}
In this code snippet, the only statement that does some work is Console.WriteLine(“Hello World!”);. All the remaining...