Primary Constructors and private fields naming convention #7565
-
The C# style guide recommends prefixing internal and private variables with
With primary constructors, this advice becomes outdated or problematic since the primary constructor arguments are not prefixed We will either:
My question is, will that style guide be updated to suggest a way forward? Is there already a consensus? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 19 replies
-
Primary constructor parameters aren't fields as far as the C# language is concerned. They are captures, and the actual mechanism used to capture the value of the parameter beyond the lifecycle of the constructor (if necessary) is an implementation detail. So I think the naming guideline would be to treat them as normal parameters, as you would do with method parameters that are captured by lambdas. |
Beta Was this translation helpful? Give feedback.
Primary constructor parameters aren't fields as far as the C# language is concerned. They are captures, and the actual mechanism used to capture the value of the parameter beyond the lifecycle of the constructor (if necessary) is an implementation detail. So I think the naming guideline would be to treat them as normal parameters, as you would do with method parameters that are captured by lambdas.