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

Why method assigns the parameter to refer to a different object aren't visible from the caller, when pass a value type by reference? #41087

Open
Unarimit opened this issue May 27, 2024 · 3 comments
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3

Comments

@Unarimit
Copy link

Type of issue

Typo

Description

Does it mean such method as void foo(ref int num) is not reasonable? I can not got it.

Page URL

https://learn.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/method-parameters

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/keywords/method-parameters.md

Document Version Independent Id

7241f712-8d73-b5e0-37c0-5f05c92412c6

Article author

@BillWagner

Metadata

  • ID: b8dd92fe-5053-1bc6-1c8f-cf9f88635cb5
  • Service: dotnet-csharp
  • Sub-service: lang-reference
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label May 27, 2024
@issues-automation issues-automation bot added dotnet-csharp/svc lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3 labels May 27, 2024
@Unarimit
Copy link
Author

@BillWagner BillWagner added the doc-enhancement Improve the current content [org][type][category] label May 28, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label May 28, 2024
@BillWagner
Copy link
Member

We should update this page and introduce the term "referent", which as added to the standard in C# 7.3. Then, that can clarify how a ref argument can be assigned:

  • Assigning a new value changes the value of the current referent: num = 12; That change is visible outside the method
  • Ref assigning to change the referent means the variable refers to different storage: num ref = someVariable; That change won't be visible outside the method.

Adding this to our backlog to fix on our next update in this section.

@Unarimit
Copy link
Author

We should update this page and introduce the term "referent", which as added to the standard in C# 7.3. Then, that can clarify how a ref argument can be assigned:

  • Assigning a new value changes the value of the current referent: num = 12; That change is visible outside the method
  • Ref assigning to change the referent means the variable refers to different storage: num ref = someVariable; That change won't be visible outside the method.

Adding this to our backlog to fix on our next update in this section.

Thank you for your reply. Yeah, a new feature🥲

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

No branches or pull requests

3 participants