Last active
December 14, 2015 23:09
-
-
Save jaredpar/5163187 to your computer and use it in GitHub Desktop.
Fun with booleans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
[StructLayout(LayoutKind.Explicit)] | |
struct Union | |
{ | |
[FieldOffset(0)] | |
internal byte ByteField; | |
[FieldOffset(0)] | |
internal bool BoolField; | |
} | |
static void Main(string[] args) | |
{ | |
Union u1 = new Union(); | |
Union u2 = new Union(); | |
u1.ByteField = 1; | |
u2.ByteField = 2; | |
bool b1 = u1.BoolField; | |
bool b2 = u2.BoolField; | |
Console.WriteLine(b1 & b2); // False | |
Console.WriteLine(b1 && b2); // True | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment