Created
December 13, 2019 18:11
-
-
Save TessenR/b65e73ed737ed6eef04a4d891a13fcae to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Runtime.InteropServices; | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
bool b = GetTricksyBool(); | |
if (b) Console.WriteLine(b.IsTrue()); | |
} | |
static bool IsTrue(this bool b) | |
{ | |
bool bTrue = true; | |
bool bFalse = false;; | |
if (b == bTrue) | |
{ | |
return true; | |
} | |
else if (b == bFalse) | |
{ | |
return false; | |
} | |
else | |
{ | |
return !true && !false; | |
} | |
} | |
static bool GetTricksyBool() => new Magic() { i = 42 }.b; | |
[StructLayout(LayoutKind.Explicit)] | |
class Magic | |
{ | |
[FieldOffset(0)] public int i; | |
[FieldOffset(0)] public bool b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment