Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoping private variables within a class #1712

Closed
stokara opened this issue Jul 13, 2018 · 6 comments
Closed

Scoping private variables within a class #1712

stokara opened this issue Jul 13, 2018 · 6 comments

Comments

@stokara
Copy link

stokara commented Jul 13, 2018

In my most common use case of property backing fields I would like to be able to be sure that the private field is not modified externally to the property setter. To visually indicate this I commonly declare the field above the property. It would be great to have this ensured by the compiler by having the variable scoped within the property perhaps like this:

public Type PropertyName {
private Type field;
get => field;
set => setMethod(ref field, value);
}

@Joe4evr
Copy link
Contributor

Joe4evr commented Jul 13, 2018

#1643, #140, #1497, etc.

@bondsbw
Copy link

bondsbw commented Jul 13, 2018

#133

@AustinBryan
Copy link

A better name for this would be "property scoped variables." Also, please reformat your code

@Unknown6656
Copy link
Contributor

Unknown6656 commented Jul 16, 2018

Oh boy - here we go again with the duplicates:

See #1497 (comment)

And ...
#1643
#1497
#1420
#1336
#1290
#1240
(#1059)
#626
#318
#140
#133
[and there are probably even more]

@stokara
Copy link
Author

stokara commented Jul 16, 2018

mea culpa - I did this without searching.

@Unknown6656
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants