Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void Examples()

Console.WriteLine("==== Additional examples");
CompoundAssignment();
CompoundAssignmentWithCast();
Precedence();
}

Expand Down Expand Up @@ -81,6 +82,17 @@ private static void LeftShift()
// Before: 11001001000000000000000000010001
// After: 10010000000000000000000100010000
// </SnippetLeftShift>

// <SnippetLeftShiftPromoted>
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
// </SnippetLeftShiftPromoted>
}

private static void RightShift()
Expand Down Expand Up @@ -156,6 +168,19 @@ private static void CompoundAssignment()
// </SnippetCompoundAssignment>
}

private static void CompoundAssignmentWithCast()
{
// <SnippetCompoundAssignmentWithCast>
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
// </SnippetCompoundAssignmentWithCast>
}

private static void Precedence()
{
// <SnippetPrecedence>
Expand Down