From c6a86516839d1947d5ec210a3aaa03af62fa0baa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:48:18 +0000 Subject: [PATCH 1/4] Initial plan From 33ad624525ec7536737cedcc76e9c4e8df5c2e75 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 19:03:01 +0000 Subject: [PATCH 2/4] Update CS0524 documentation to reflect C# 8.0 changes Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/misc/cs0524.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/csharp/misc/cs0524.md b/docs/csharp/misc/cs0524.md index 949d57811f3e0..10ffb7a521441 100644 --- a/docs/csharp/misc/cs0524.md +++ b/docs/csharp/misc/cs0524.md @@ -1,7 +1,7 @@ --- description: "Compiler Error CS0524" title: "Compiler Error CS0524" -ms.date: 07/20/2015 +ms.date: 01/02/2025 f1_keywords: - "CS0524" helpviewer_keywords: @@ -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 would have generated CS0524 in C# versions prior to 8.0, but is now valid code: ```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) From 3e802779588201d8c8ee710971ded61f3c3a6b18 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:15:39 +0000 Subject: [PATCH 3/4] Update ms.date to 07/31/2025 as requested Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/misc/cs0524.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/misc/cs0524.md b/docs/csharp/misc/cs0524.md index 10ffb7a521441..fbe5fbb7a23a6 100644 --- a/docs/csharp/misc/cs0524.md +++ b/docs/csharp/misc/cs0524.md @@ -1,7 +1,7 @@ --- description: "Compiler Error CS0524" title: "Compiler Error CS0524" -ms.date: 01/02/2025 +ms.date: 07/31/2025 f1_keywords: - "CS0524" helpviewer_keywords: From f7b8a652f863eb586deeff7d72aecb4a26ccb395 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:05:49 +0000 Subject: [PATCH 4/4] Improve wording as suggested by @gewarren Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --- docs/csharp/misc/cs0524.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/misc/cs0524.md b/docs/csharp/misc/cs0524.md index fbe5fbb7a23a6..d373390fe06d0 100644 --- a/docs/csharp/misc/cs0524.md +++ b/docs/csharp/misc/cs0524.md @@ -18,7 +18,7 @@ In modern C# (C# 8.0 and later), this error is no longer generated for nested ty ## Historical example -The following sample would have generated CS0524 in C# versions prior to 8.0, but is now valid code: +The following sample generates CS0524 in C# versions prior to 8.0, but is valid in modern C# versions: ```csharp // This code is valid in C# 8.0 and later