Only a compilation unit can have top-level units. Error

Enes Harun 0 Reputation points
2024-11-24T14:22:06.73+00:00

Only a compilation unit can have top-level units. I couldn't find what caused this error. I don't know what this error means and if there is a solution. Can you help me? I am using Visual Studio Code with .NET9.0 version and C# coding language.

Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
    2024-11-24T17:39:05.51+00:00

    C# only support top level statements(code not contained in class definitions) in one file per project. These top level will be converted to main(){} statements at compile time. Typically it is the program.cs file.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.