A few days ago I wanted to create a simple C# Console Application. And faced with the error: “error cs8803: Top-level statements must precede namespace and type declarations“. My problem was that I started to add types to the Program.cs file:
After I moved the Person class declaration into a separate file error disappeared:
Thus my problem was in mixing top-level statements and non-TLS.
- Visual Studio 2022
- Console Application .NET 6