procedural programming in C# leads to CS0116 error

92 Views Asked by At

I am following this Scott Hanselman's tutorial, where he shows how one could write programs in procedural style without any boilerplate in C#. So I am trying to use the compiler preinstalled on my Windows OS:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe

to compile a simple Hello World program:

// test.cs
System.Console.WriteLine("Hello World!");

using csc.exe test.cs

though I am getting the error message:

error CS0116: A namespace cannot directly contain members such as fields or methods

I am wondering if what Scott Hanselman is doing is a new feature not available to the built-in compiler version coming with the operating system, or if there are compiler options to ignore this kind of issues? I could not find any relevant entries when looking into csc /?.

P.S.1. This is a follow-up to this Discord question and this Tweet.

P.S.2. seeing responses here on Discord, it seems to be a new feature.

0

There are 0 best solutions below