From 83dc9f0d7b7ca08fcead03c413baa96884900523 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:09:36 +0000 Subject: [PATCH 1/3] Initial plan From 221d4d96a32dae39f64f315ef0d6560037f7414f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:16:03 +0000 Subject: [PATCH 2/3] Fix static field documentation for generic types Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/language-reference/keywords/static.md | 2 +- docs/csharp/misc/cs1914.md | 2 +- .../static-classes-and-static-class-members.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/csharp/language-reference/keywords/static.md b/docs/csharp/language-reference/keywords/static.md index 3e849576fefdb..6a233e554fa99 100644 --- a/docs/csharp/language-reference/keywords/static.md +++ b/docs/csharp/language-reference/keywords/static.md @@ -39,7 +39,7 @@ To refer to the `static` member `x`, use the fully qualified name, `MyBaseC.MySt Console.WriteLine(MyBaseC.MyStruct.x); ``` -While an instance of a class contains a separate copy of all instance fields of the class, there's only one copy of each `static` field. +While an instance of a class contains a separate copy of all instance fields of the class, there's only one copy of each `static` field. For generic types, each closed generic type has its own copy of static fields. It isn't possible to use [`this`](this.md) to reference `static` methods or property accessors. diff --git a/docs/csharp/misc/cs1914.md b/docs/csharp/misc/cs1914.md index 8ddf70ddf4a11..c0a7cdbed03a9 100644 --- a/docs/csharp/misc/cs1914.md +++ b/docs/csharp/misc/cs1914.md @@ -12,7 +12,7 @@ ms.assetid: e61361b6-4660-41fd-a574-cc48e1b3873c Static field 'name' cannot be assigned in an object initializer - Object initializers by definition initialize objects, or instances, of classes. They cannot be used to initialize a `static` field of a type. No matter how many instances of a class are created, there is only one copy of a `static` field. + Object initializers by definition initialize objects, or instances, of classes. They cannot be used to initialize a `static` field of a type. No matter how many instances of a class are created, there is only one copy of a `static` field. For generic types, each closed generic type has its own copy of static fields. ## To correct this error diff --git a/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md b/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md index a23fbbb92f42b..6bd1395f33149 100644 --- a/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md +++ b/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md @@ -59,7 +59,7 @@ Console.WriteLine(Math.Round(Math.Abs(dub))); ## Static Members - A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class exists. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties can't access non-static fields and events in their containing type, and they can't access an instance variable of any object unless it's explicitly passed in a method parameter. + A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class exists. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. For generic types, each closed generic type has its own copy of static members. Static methods and properties can't access non-static fields and events in their containing type, and they can't access an instance variable of any object unless it's explicitly passed in a method parameter. It's more typical to declare a non-static class with some static members, than to declare an entire class as static. Two common uses of static fields are to keep a count of the number of objects that are instantiated, or to store a value that must be shared among all instances. From 578c65804be02be42d0694ba27cb8bce0c119ff6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 21:18:44 +0000 Subject: [PATCH 3/3] Add ThreadStatic clarification to static field documentation Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- docs/csharp/language-reference/keywords/static.md | 2 +- docs/csharp/misc/cs1914.md | 2 +- .../static-classes-and-static-class-members.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/csharp/language-reference/keywords/static.md b/docs/csharp/language-reference/keywords/static.md index 6a233e554fa99..1f6d5c43abc9c 100644 --- a/docs/csharp/language-reference/keywords/static.md +++ b/docs/csharp/language-reference/keywords/static.md @@ -39,7 +39,7 @@ To refer to the `static` member `x`, use the fully qualified name, `MyBaseC.MySt Console.WriteLine(MyBaseC.MyStruct.x); ``` -While an instance of a class contains a separate copy of all instance fields of the class, there's only one copy of each `static` field. For generic types, each closed generic type has its own copy of static fields. +While an instance of a class contains a separate copy of all instance fields of the class, there's only one copy of each `static` field. For generic types, each closed generic type has its own copy of static fields. Static fields marked with have one copy per thread. It isn't possible to use [`this`](this.md) to reference `static` methods or property accessors. diff --git a/docs/csharp/misc/cs1914.md b/docs/csharp/misc/cs1914.md index c0a7cdbed03a9..7aa405d5377e4 100644 --- a/docs/csharp/misc/cs1914.md +++ b/docs/csharp/misc/cs1914.md @@ -12,7 +12,7 @@ ms.assetid: e61361b6-4660-41fd-a574-cc48e1b3873c Static field 'name' cannot be assigned in an object initializer - Object initializers by definition initialize objects, or instances, of classes. They cannot be used to initialize a `static` field of a type. No matter how many instances of a class are created, there is only one copy of a `static` field. For generic types, each closed generic type has its own copy of static fields. + Object initializers by definition initialize objects, or instances, of classes. They cannot be used to initialize a `static` field of a type. No matter how many instances of a class are created, there is only one copy of a `static` field. For generic types, each closed generic type has its own copy of static fields. Static fields marked with have one copy per thread. ## To correct this error diff --git a/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md b/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md index 6bd1395f33149..f898e3e72b42b 100644 --- a/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md +++ b/docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md @@ -59,7 +59,7 @@ Console.WriteLine(Math.Round(Math.Abs(dub))); ## Static Members - A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class exists. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. For generic types, each closed generic type has its own copy of static members. Static methods and properties can't access non-static fields and events in their containing type, and they can't access an instance variable of any object unless it's explicitly passed in a method parameter. + A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class exists. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. For generic types, each closed generic type has its own copy of static members. Static fields marked with have one copy per thread. Static methods and properties can't access non-static fields and events in their containing type, and they can't access an instance variable of any object unless it's explicitly passed in a method parameter. It's more typical to declare a non-static class with some static members, than to declare an entire class as static. Two common uses of static fields are to keep a count of the number of objects that are instantiated, or to store a value that must be shared among all instances.