.NET 6 new program style vs .NET 5 old program style

Greetings and salutations!

I have some basic knowledge of programming, but a complete beginner with C#.

I’m a bit confused with the new vs old program style.

I’m using VS Studio community with .NET6 and from what I understand the term top-level statements means the compiler generates the namespace, class, and method elements for the main program. Mostly works, but sometimes this creates errors when I try to follow along.

Should I go back to .NET5 or I’ll be ok with .NET6?

Besides the Windows docs, I didn’t find much info on this.

Thanks!

I think you should be able to use the old style even in .NET6. Have you tried it?

Thanks for the reply!

Hey I think you’re right. Seems I can create the project in .NET5, then change the framework settings to .NET 6. Should be all good.

Cheers,

Interesting discussion

Hi,
That would be interesting to have more details on what is not working for you with Top-Level Statement syntax.

Just remember that in the Program.cs file, this is like you’d be coding within the Main method.

You cannot define static methods in the same file for instance. You’ll need to import extra code from another file.

Cheers.