Skip to content

Commit f35d1ee

Browse files
Update cs8862 constructor error (#47690)
* Update access-modifiers.md Added description for file access type modifier * Update constructor-errors.md * Update constructor-errors.md * Update docs/csharp/language-reference/compiler-messages/constructor-errors.md --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent efc20dc commit f35d1ee

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/csharp/language-reference/compiler-messages/constructor-errors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ The compiler emits the following errors when a primary constructor violates one
257257
- **CS9124**: *Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.*
258258
- **CS9136**: *Cannot use primary constructor parameter of type inside an instance member.*
259259

260+
When using a primary constructor in a class or struct, every explicitly declared constructor must call the primary constructor using `: this(...)` with an appropriate argument list. This ensures that the primary constructor is always invoked. For more information on primary constructors, see the article on [instance constructors](../../programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) in the programming guide.
261+
260262
Primary constructor parameters are in scope in the body of that type. The compiler can synthesize a field that stores the parameter for use in members or in field initializers. Because a primary constructor parameter may be copied to a field, the following restrictions apply:
261263

262264
- Primary constructors can be declared on `struct` and `class` types, but not on `interface` types.

0 commit comments

Comments
 (0)