Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Semantics of bool fields in explicit layout types (ECMA-334)
- static void Main(string[] args)
- {
- TestStruct a = new TestStruct();
- a.byteValue = 1;
- TestStruct b = new TestStruct();
- b.byteValue = 2;
- Console.WriteLine(string.Format("Result of {0}=={1} is {2}.",
- a.boolValue, b.boolValue, a.boolValue == b.boolValue));
- Console.WriteLine(string.Format("Result of {0}!={1} is {2}.",
- a.boolValue, b.boolValue, a.boolValue != b.boolValue));
- Console.WriteLine(string.Format("Result of {0}^{1} is {2}.",
- a.boolValue, b.boolValue, a.boolValue ^ b.boolValue));
- }
- [StructLayout(LayoutKind.Explicit, Pack = 1)]
- struct TestStruct
- {
- [FieldOffset(0)]
- public bool boolValue;
- [FieldOffset(0)]
- public byte byteValue;
- }
- Result of True==True is False.
- Result of True!=True is True.
- Result of True^True is True.
Add Comment
Please, Sign In to add comment