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

Initial page of CS8802 error #43728

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/csharp/language-reference/compiler-messages/cs8802.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
description: "Compiler Error CS8802"
title: "Compiler Error CS8802"
ms.date: 7/01/2024
f1_keywords:
- "CS8802"
helpviewer_keywords:
- "CS8802"
---
# Compiler Error CS8802

Only one compilation unit can have top-level statements.

This error indicates that there are two or more [top-level statements](../../fundamentals/program-structure/top-level-statements.md) in a single compilation unit (single solution, project or a single group of files compiled into a single binary file).

## Example

The following sample of single compilation unit generates CS8802:

```xml
<!-- SingleCompilationUnit.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
```

```csharp
// EntryFile.cs

int a = 0;
```

```csharp
// SecondaryEntryFile.cs

int b = 1; // CS8802: The top level statement already exists in EntryFile.cs
```

## To correct this error

Use only one top-level statement in the project.
<br/>Top-level statements acts as an entry point to the program, so only one file may have top-level statement. All other statements must be defined as members of classes or structs.

## See also

- [Top-level statements](../../fundamentals/program-structure/top-level-statements.md)
- [CS8803](./cs8803.md)
Loading