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: standard/structs.md
+24-20Lines changed: 24 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@ With classes, it is possible for two variables to reference the same object, and
164
164
<!-- markdownlint-disableMD028 -->
165
165
166
166
<!-- markdownlint-enableMD028 -->
167
-
> *Example*: Giventhedeclaration
167
+
> *Example*: Giventhefollowing
168
168
>
169
169
> ```csharp
170
170
> structPoint
@@ -177,18 +177,20 @@ With classes, it is possible for two variables to reference the same object, and
177
177
>this.y=y;
178
178
> }
179
179
> }
180
-
> ```
181
-
>
182
-
>thecodefragment
183
180
>
184
-
> ```csharp
185
-
>Pointa=newPoint(10, 10);
186
-
>Pointb=a;
187
-
>a.x=100;
188
-
>System.Console.WriteLine(b.x);
189
-
> ```
181
+
>classA
182
+
> {
183
+
> staticvoidMain()
184
+
> {
185
+
>Pointa=newPoint(10, 10);
186
+
>Pointb=a;
187
+
>a.x=100;
188
+
>System.Console.WriteLine(b.x);
189
+
> }
190
+
> }>
191
+
> ```
190
192
>
191
-
>outputsthevalue `10`. Theassignmentof `a` to `b` createsacopyofthevalue, and `b` isthusunaffectedbytheassignmentto `a.x`. Had `Point` insteadbeendeclaredasaclass, theoutputwouldbe `100` because `a` and `b` wouldreferencethesameobject.
193
+
>theoutputis `10`. Theassignmentof `a` to `b` createsacopyofthevalue, and `b` isthusunaffectedbytheassignmentto `a.x`. Had `Point` insteadbeendeclaredasaclass, theoutputwouldbe `100` because `a` and `b` wouldreferencethesameobject.
192
194
>
193
195
>*endexample*
194
196
@@ -287,7 +289,7 @@ The meaning of `this` in a struct differs from the meaning of `this` in a class,
287
289
>Tx=newT();
288
290
>Console.WriteLine(x.ToString());
289
291
>Console.WriteLine(x.ToString());
290
-
>console.WriteLine(x.ToString());
292
+
>Console.WriteLine(x.ToString());
291
293
> }
292
294
>
293
295
> staticvoidMain() =>Test<Counter>();
@@ -375,7 +377,7 @@ As described in [§15.4.5](structs.md#1545-default-values), the default value of
375
377
376
378
Unlikeaclass, astructis not permitted to declare a parameterless instance constructor. Instead, every struct implicitly has a parameterless instance constructor, which always returns the value that results from setting all value type fields to their default value and all reference type fields to `null` ([§8.3.3](types.md#833-default-constructors)). A struct can declare instance constructors having parameters.
377
379
378
-
> *Example*:
380
+
> *Example*:Giventhefollowing
379
381
>
380
382
> ```csharp
381
383
> structPoint
@@ -388,16 +390,18 @@ Unlike a class, a struct is not permitted to declare a parameterless instance co
388
390
>this.y=y;
389
391
> }
390
392
> }
391
-
> ```
392
393
>
393
-
>Giventheabovedeclaration, thestatements
394
-
>
395
-
> ```csharp
396
-
>Pointp1=newPoint();
397
-
>Pointp2=newPoint(0, 0);
394
+
>classA
395
+
> {
396
+
> staticvoidMain()
397
+
> {
398
+
>Pointp1=newPoint();
399
+
>Pointp2=newPoint(0, 0);
400
+
> }
401
+
> }
398
402
> ```
399
403
>
400
-
>bothcreatea `Point` with `x` and `y` initializedtozero.
404
+
>thestatementsbothcreatea `Point` with `x` and `y` initializedtozero.
0 commit comments