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

[Proposal] Extend readonly members to classes and interfaces #3531

Closed
leandromoh opened this issue Jun 4, 2020 · 5 comments
Closed

[Proposal] Extend readonly members to classes and interfaces #3531

leandromoh opened this issue Jun 4, 2020 · 5 comments

Comments

@leandromoh
Copy link
Contributor

We already have readonly members, introduced in C# 8, but it works just on structs.

Can we have extend this feature for classes and interfaces take benefits too?

@leandromoh leandromoh changed the title [Proposal] Extend readonly members on classes and interfaces [Proposal] Extend readonly members to classes and interfaces Jun 4, 2020
@HaloFour
Copy link
Contributor

HaloFour commented Jun 4, 2020

The benefit of readonly members on structs is to inform the compiler that it doesn't have to make a defensive copy when calling those members when the struct is in a memory location that should not be modified, like a readonly field or in parameter. That situation doesn't exist for reference types.

@huoyaoyuan
Copy link
Member

If we have some concept of readonly instance of reference type in the future, extending readonly members will be useful then.

@Joe4evr
Copy link
Contributor

Joe4evr commented Jun 4, 2020

Duplicate of #3055. Specifically read this post on why this is very likely never happening.

@leandromoh
Copy link
Contributor Author

leandromoh commented Jun 4, 2020

I did not know that for structs the target was compiler. What I have in mind was help developers write/read methods without side-effects, or at least, delimit it.

@333fred
Copy link
Member

333fred commented Jun 4, 2020

Closing as a duplicate.

@333fred 333fred closed this as completed Jun 4, 2020
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