Guest User

Untitled

a guest
Sep 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Semantics of bool fields in explicit layout types (ECMA-334)
  2. static void Main(string[] args)
  3. {
  4. TestStruct a = new TestStruct();
  5. a.byteValue = 1;
  6. TestStruct b = new TestStruct();
  7. b.byteValue = 2;
  8.  
  9. Console.WriteLine(string.Format("Result of {0}=={1} is {2}.",
  10. a.boolValue, b.boolValue, a.boolValue == b.boolValue));
  11. Console.WriteLine(string.Format("Result of {0}!={1} is {2}.",
  12. a.boolValue, b.boolValue, a.boolValue != b.boolValue));
  13. Console.WriteLine(string.Format("Result of {0}^{1} is {2}.",
  14. a.boolValue, b.boolValue, a.boolValue ^ b.boolValue));
  15. }
  16.  
  17. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  18. struct TestStruct
  19. {
  20. [FieldOffset(0)]
  21. public bool boolValue;
  22. [FieldOffset(0)]
  23. public byte byteValue;
  24. }
  25.  
  26. Result of True==True is False.
  27. Result of True!=True is True.
  28. Result of True^True is True.
Add Comment
Please, Sign In to add comment