DEV Community

Wriju's Blog
Wriju's Blog

Posted on

C# 9.0 - Optional "Main"

To run a C# code now we don't need namespace, main etc. Just run it

using System;

Console.WriteLine("Hello one line C# 9.0");

//namespace CSharp9
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            Console.WriteLine("Hello one line C# 9.0"); 
//        }
//    }
//}
Enter fullscreen mode Exit fullscreen mode

Even this works

using System;

Console.WriteLine("Hello one line C# 9.0");
Console.WriteLine("Hello one line C# 9.0");
if (1 == 1)
{
    Console.WriteLine("if con");
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)