Share via

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#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,821 Reputation points
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.