Skip to content

Instantly share code, notes, and snippets.

@TessenR
Created December 13, 2019 18:11
Show Gist options
  • Save TessenR/b65e73ed737ed6eef04a4d891a13fcae to your computer and use it in GitHub Desktop.
Save TessenR/b65e73ed737ed6eef04a4d891a13fcae to your computer and use it in GitHub Desktop.
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