Skip to content

Update CS0524 documentation to reflect C# 8.0 changes allowing nested types in interfaces #47669

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

Merged
merged 4 commits into from
Aug 4, 2025
Merged
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
24 changes: 16 additions & 8 deletions docs/csharp/misc/cs0524.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Compiler Error CS0524"
title: "Compiler Error CS0524"
ms.date: 07/20/2015
ms.date: 07/31/2025
f1_keywords:
- "CS0524"
helpviewer_keywords:
Expand All @@ -12,18 +12,26 @@ ms.assetid: a5cd8fb0-f5df-4580-9116-a6be4dffd1cb

'type' : interfaces cannot declare types

An [interface](../language-reference/keywords/interface.md) cannot contain a user-defined type; it should contain only methods and properties.

## Example
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.

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.

## Historical example

The following sample generates CS0524:
The following sample generates CS0524 in C# versions prior to 8.0, but is valid in modern C# versions:

```csharp
// CS0524.cs
public interface Clx
// This code is valid in C# 8.0 and later
public interface IExample
{
public class Cly // CS0524, delete user-defined type
public class NestedClass // Valid since C# 8.0
{
}
}
```

## See also

- [Interfaces](../language-reference/keywords/interface.md)
- [Nested types](../programming-guide/classes-and-structs/nested-types.md)
- [What's new in C# version history](../whats-new/csharp-version-history.md#c-version-80)