Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error CS8802: Only one compilation unit can have top-level statements. #38811

Closed
soujanya30 opened this issue Dec 17, 2023 · 4 comments · Fixed by #43728
Closed

error CS8802: Only one compilation unit can have top-level statements. #38811

soujanya30 opened this issue Dec 17, 2023 · 4 comments · Fixed by #43728
Labels
csharp-diagnostics/tech doc-enhancement Improve the current content [org][type][category] dotnet-csharp/prod dotnet-csharp/svc errors-warnings/subsvc in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3

Comments

@soujanya30
Copy link

Type of issue

Missing information

Description

[Enter feedback here]
"error CS8802: Only one compilation unit can have top-level statements." is displaying in my device please fix it

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error?f1url=%3FappId%3Droslyn%26k%3Dk(CS8802)

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md

Document Version Independent Id

58a19505-ac46-c5c8-12cc-fe87b6aa18a7

Article author

@BillWagner

Metadata

  • ID: bbb051ee-f020-66ba-c601-4a08ad32ef61
  • Product: dotnet-csharp
  • Technology: csharp-diagnostics
@BillWagner
Copy link
Member

Hi @soujanya30

This is one of the issues we need to add help for. Thanks for pointing that out.

One file in a C# program can contain top level statements. Those top level statements represent the entry point to the program. (This would often be the Main method in earlier C# versions or other languages).

Because it's the entry point to the program, only one file may have top level statements. All other statements must be in members defined in classes or structs.

@BillWagner BillWagner added the doc-enhancement Improve the current content [org][type][category] label Dec 18, 2023
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Dec 18, 2023
@soujanya30
Copy link
Author

so what should i do to start c# in all file in place of only one file , please provide a solution for it

@BillWagner
Copy link
Member

Hi @soujanya30

We've got a few articles that will help. I recommend starting with this article on top-level statements. Then, this tutorial has an introduction to classes,

Finally, when you get stuck, post a short sample to our Q & A site. There are a number of folks that can answer these specific questions.

@dotnet-policy-service dotnet-policy-service bot added the in-pr This issue will be closed (fixed) by an active pull request. label Nov 23, 2024
@zashab
Copy link

zashab commented Nov 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csharp-diagnostics/tech doc-enhancement Improve the current content [org][type][category] dotnet-csharp/prod dotnet-csharp/svc errors-warnings/subsvc in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants