dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.16k stars 5.83k forks source link

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 1 month ago

Unarimit commented 1 month ago

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

Unarimit commented 1 month ago

this issue appear in this subheading https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#combinations-of-parameter-type-and-argument-mode

BillWagner commented 1 month ago

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:

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

Unarimit commented 1 month ago

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🥲