You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/operators/assignment-operator.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Assignment operators - assign an expression to a variable"
3
-
description: "C# assignment operators assign an expression to a variable. Assignment sets the value of the expression. `ref` assignment sets the reference of a `ref` variable."
4
-
ms.date: 11/29/2022
3
+
description: "C# Assignment sets the value of the expression. Alternatively, `ref` assignment sets the reference of a reference variable."
4
+
ms.date: 11/19/2024
5
5
f1_keywords:
6
6
- "=_CSharpKeyword"
7
7
helpviewer_keywords:
@@ -18,7 +18,7 @@ The assignment operator `=` is right-associative, that is, an expression of the
18
18
a=b=c
19
19
```
20
20
21
-
isevaluatedas
21
+
Isevaluatedas
22
22
23
23
```csharp
24
24
a= (b=c)
@@ -30,7 +30,7 @@ The following example demonstrates the usage of the assignment operator with a l
@@ -42,6 +42,14 @@ In the preceding example, the [local reference variable](../statements/declarati
42
42
43
43
Theleft-handoperandof `ref` assignmentcanbea [localreferencevariable](../statements/declarations.md#reference-variables), a [`ref` field](../builtin-types/ref-struct.md#ref-fields), anda [`ref`](../keywords/ref.md), [`out`](../keywords/method-parameters.md#out-parameter-modifier), or [`in`](../keywords/method-parameters.md#in-parameter-modifier) methodparameter. Bothoperandsmustbeofthesametype.
44
44
45
+
A `ref` assignmentmeansthatareferencevariablehasadifferentreferrent. It's no longer referring to its previous referrent. Using `ref =` on a `ref` parameter means the parameter no longer refers to its argument. Any actions that modify the state of the object after ref reassigning it make those modifications to the new item. For example, consider the following method:
Thefollowingusageshowsthattheassignmenttotheparameter `s` isn't visible after the method call because `s` was `ref` reassigned to refer to `sLocal` before the string was modified:
@@ -50,15 +58,15 @@ For a binary operator `op`, a compound assignment expression of the form
50
58
xop=y
51
59
```
52
60
53
-
isequivalentto
61
+
Isequivalentto
54
62
55
63
```csharp
56
64
x=xopy
57
65
```
58
66
59
-
exceptthat `x` isonlyevaluatedonce.
67
+
Exceptthat `x` isonlyevaluatedonce.
60
68
61
-
Compoundassignmentissupportedby[arithmetic](arithmetic-operators.md#compound-assignment), [Booleanlogical](boolean-logical-operators.md#compound-assignment), and [bitwiselogicalandshift](bitwise-and-shift-operators.md#compound-assignment) operators.
69
+
The[arithmetic](arithmetic-operators.md#compound-assignment), [Booleanlogical](boolean-logical-operators.md#compound-assignment), and [bitwiselogicalandshift](bitwise-and-shift-operators.md#compound-assignment) operatorsallsupportcompountassignment.
0 commit comments