diff --git a/snippets/csharp/language-reference/operators/BitwiseAndShiftOperators.cs b/snippets/csharp/language-reference/operators/BitwiseAndShiftOperators.cs index 673940ad6a9..c04249f390e 100644 --- a/snippets/csharp/language-reference/operators/BitwiseAndShiftOperators.cs +++ b/snippets/csharp/language-reference/operators/BitwiseAndShiftOperators.cs @@ -19,6 +19,7 @@ public static void Examples() Console.WriteLine("==== Additional examples"); CompoundAssignment(); + CompoundAssignmentWithCast(); Precedence(); } @@ -81,6 +82,17 @@ private static void LeftShift() // Before: 11001001000000000000000000010001 // After: 10010000000000000000000100010000 // + + // + byte a = 0b_1111_0001; + + var b = a << 8; + Console.WriteLine(b.GetType()); + Console.WriteLine($"Shifted byte: {Convert.ToString(b, toBase: 2)}"); + // Output: + // System.Int32 + // Shifted byte: 1111000100000000 + // } private static void RightShift() @@ -156,6 +168,19 @@ private static void CompoundAssignment() // } + private static void CompoundAssignmentWithCast() + { + // + byte x = 0b_1111_0001; + + int b = x << 8; + Console.WriteLine($"{Convert.ToString(b, toBase: 2)}"); // output: 1111000100000000 + + x <<= 8; + Console.WriteLine(x); // output: 0 + // + } + private static void Precedence() { //