From 69f41a89342d78b33679dd22596cad660b7ff9c0 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:36:22 +0100 Subject: [PATCH 1/3] Update access-modifiers.md Added description for file access type modifier --- .../programming-guide/classes-and-structs/access-modifiers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md index 5543714e1a752..2fc42d93fb2ac 100644 --- a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md +++ b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md @@ -73,6 +73,8 @@ To set the access level for a `class` or `struct` member, add the appropriate ke Finalizers can't have accessibility modifiers. Members of an `enum` type are always `public`, and no access modifiers can be applied. +The `file` access modifier is allowed only on top-level (non-nested) type declarations. + ## C# language specification [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] From 7c1c4412402c2a3a789e9a29b1bc1bfd1358416d Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Thu, 21 Aug 2025 10:54:09 +0100 Subject: [PATCH 2/3] Update Program.cs Add an example to show parameterless static and instance constructors in a single class. --- .../snippets/constructors/Program.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/csharp/programming-guide/classes-and-structs/snippets/constructors/Program.cs b/docs/csharp/programming-guide/classes-and-structs/snippets/constructors/Program.cs index 9cd7ee626742a..434082552b1c9 100644 --- a/docs/csharp/programming-guide/classes-and-structs/snippets/constructors/Program.cs +++ b/docs/csharp/programming-guide/classes-and-structs/snippets/constructors/Program.cs @@ -72,3 +72,20 @@ public required T Contents } // +// +public class Example +{ + static Example() + { + Console.WriteLine("Static constructor called."); + } + + public Example() + { + Console.WriteLine("Instance constructor called."); + } + + // Remaining implementation of Child class. +} +// + From 4292bfdb37fa0ead1026a07e21093396fa8e54fa Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Thu, 21 Aug 2025 11:01:05 +0100 Subject: [PATCH 3/3] Update constructors.md Mention Static and instance constructor definiton --- .../programming-guide/classes-and-structs/constructors.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/csharp/programming-guide/classes-and-structs/constructors.md b/docs/csharp/programming-guide/classes-and-structs/constructors.md index 770a31d9aac98..c8fb566e7083b 100644 --- a/docs/csharp/programming-guide/classes-and-structs/constructors.md +++ b/docs/csharp/programming-guide/classes-and-structs/constructors.md @@ -56,6 +56,10 @@ You can also define a static constructor with an expression body definition, as For more information and examples, see [Static Constructors](./static-constructors.md). +A class can also have **both** an Instance and Static constructor defined, and they can each be defined without parameters. + +:::code source="./snippets/constructors/Program.cs" id="DualConstructor"::: + ## Partial constructors Beginning with C# 14, you can declare *partial constructors* in a partial class or struct. Any partial constructor must have a *defining declaration* and an *implementing declaration*. The signatures of the declaring and implementing partial constructors must match according to the rules of [partial members](./partial-classes-and-methods.md#partial-members). The defining declaration of the partial constructor can't use the `: base()` or `: this()` constructor initializer. You add any constructor initializer must be added on the implementing declaration.