File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
snippets/csharp/language-reference/operators Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff 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>
You can’t perform that action at this time.
0 commit comments