Skip to content

Commit 8df888d

Browse files
CopilotBillWagnergewarren
authored
Update CS0524 documentation to reflect C# 8.0 changes allowing nested types in interfaces (#47669)
* Initial plan * Update CS0524 documentation to reflect C# 8.0 changes Co-authored-by: BillWagner <[email protected]> * Update ms.date to 07/31/2025 as requested Co-authored-by: BillWagner <[email protected]> * Improve wording as suggested by @gewarren Co-authored-by: gewarren <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: gewarren <[email protected]>
1 parent 6af8c82 commit 8df888d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/csharp/misc/cs0524.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Compiler Error CS0524"
33
title: "Compiler Error CS0524"
4-
ms.date: 07/20/2015
4+
ms.date: 07/31/2025
55
f1_keywords:
66
- "CS0524"
77
helpviewer_keywords:
@@ -12,18 +12,26 @@ ms.assetid: a5cd8fb0-f5df-4580-9116-a6be4dffd1cb
1212

1313
'type' : interfaces cannot declare types
1414

15-
An [interface](../language-reference/keywords/interface.md) cannot contain a user-defined type; it should contain only methods and properties.
16-
17-
## Example
15+
Prior to C# 8.0, an [interface](../language-reference/keywords/interface.md) could not contain user-defined types. Starting with C# 8.0, interfaces can declare [nested types](../programming-guide/classes-and-structs/nested-types.md) as part of the default interface members feature.
16+
17+
In modern C# (C# 8.0 and later), this error is no longer generated for nested types in interfaces. The compiler now allows interfaces to contain nested classes, structs, interfaces, enums, and delegates.
18+
19+
## Historical example
1820

19-
The following sample generates CS0524:
21+
The following sample generates CS0524 in C# versions prior to 8.0, but is valid in modern C# versions:
2022

2123
```csharp
22-
// CS0524.cs
23-
public interface Clx
24+
// This code is valid in C# 8.0 and later
25+
public interface IExample
2426
{
25-
public class Cly // CS0524, delete user-defined type
27+
public class NestedClass // Valid since C# 8.0
2628
{
2729
}
2830
}
2931
```
32+
33+
## See also
34+
35+
- [Interfaces](../language-reference/keywords/interface.md)
36+
- [Nested types](../programming-guide/classes-and-structs/nested-types.md)
37+
- [What's new in C# version history](../whats-new/csharp-version-history.md#c-version-80)

0 commit comments

Comments
 (0)