Skip to content

Commit 6b12a9b

Browse files
BartoszKlonowskiYoussef1313BillWagner
authored
Initial page of CS8802 error (#43728)
* Create initial page of CS8802 * Link CS8803 and top-level statements to the page * Correct the ms.date in CS8802 page metadata Co-authored-by: Youssef Victor <[email protected]> * Remove CS8802 from list of missing pages * Remove solution from single compilation unit explanation A solution can, for example, contain multiple console applications. Co-authored-by: Bill Wagner <[email protected]> --------- Co-authored-by: Youssef Victor <[email protected]> Co-authored-by: Bill Wagner <[email protected]>
1 parent 9819404 commit 6b12a9b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
description: "Compiler Error CS8802"
3+
title: "Compiler Error CS8802"
4+
ms.date: 11/24/2024
5+
f1_keywords:
6+
- "CS8802"
7+
helpviewer_keywords:
8+
- "CS8802"
9+
---
10+
# Compiler Error CS8802
11+
12+
Only one compilation unit can have top-level statements.
13+
14+
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 project or a single group of files compiled into a single binary file).
15+
16+
## Example
17+
18+
The following sample of single compilation unit generates CS8802:
19+
20+
```xml
21+
<!-- SingleCompilationUnit.csproj -->
22+
<Project Sdk="Microsoft.NET.Sdk">
23+
<PropertyGroup>
24+
<TargetFramework>net8.0</TargetFramework>
25+
</PropertyGroup>
26+
</Project>
27+
```
28+
29+
```csharp
30+
// EntryFile.cs
31+
32+
int a = 0;
33+
```
34+
35+
```csharp
36+
// SecondaryEntryFile.cs
37+
38+
int b = 1; // CS8802: The top level statement already exists in EntryFile.cs
39+
```
40+
41+
## To correct this error
42+
43+
Use only one top-level statement in the project.
44+
<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.
45+
46+
## See also
47+
48+
- [Top-level statements](../../fundamentals/program-structure/top-level-statements.md)
49+
- [CS8803](./cs8803.md)

docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ f1_keywords:
425425
- "CS8793"
426426
- "CS8794"
427427
- "CS8801"
428-
- "CS8802"
429428
- "CS8804"
430429
- "CS8805"
431430
- "CS8806"

0 commit comments

Comments
 (0)