Skip to content

Commit e2bbbfe

Browse files
pkulikovBillWagner
authored andcommitted
Arithmetic operators: added example of a compound assignment with cast (#825)
1 parent 34ccda4 commit e2bbbfe

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

snippets/csharp/language-reference/operators/ArithmeticOperators.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static void Examples()
2828

2929
Console.WriteLine("==== Compound assignment");
3030
CompoundAssignment();
31+
CompoundAssignmentWithCast();
3132

3233
Console.WriteLine("==== Special cases");
3334
CheckedUnchecked();
@@ -194,6 +195,21 @@ private static void CompoundAssignment()
194195
// </SnippetCompoundAssignment>
195196
}
196197

198+
private static void CompoundAssignmentWithCast()
199+
{
200+
// <SnippetCompoundAssignmentWithCast>
201+
byte a = 200;
202+
byte b = 100;
203+
204+
var c = a + b;
205+
Console.WriteLine(c.GetType()); // output: System.Int32
206+
Console.WriteLine(c); // output: 300
207+
208+
a += b;
209+
Console.WriteLine(a); // output: 44
210+
// </SnippetCompoundAssignmentWithCast>
211+
}
212+
197213
private static void CheckedUnchecked()
198214
{
199215
// <SnippetCheckedUnchecked>

0 commit comments

Comments
 (0)