Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active December 17, 2015 02:29
Show Gist options
  • Save Porges/5536010 to your computer and use it in GitHub Desktop.
Save Porges/5536010 to your computer and use it in GitHub Desktop.
class Program {
static bool M(out int x)
{
x = 123;
return true;
}
static int N(EvilBool d)
{
int y = 3;
if (d || M(out y))
y = 10;
return y;
}
static void Main()
{
var result = N(new EvilBool());
// Prints 3!
Console.WriteLine(result);
}
}
class EvilBool
{
private bool value;
public static bool operator true(EvilBool b)
{
return b.Value;
}
public bool Value
{
// Return true the first time this is called
// and false the second time
get
{
value = !value;
return value;
}
}
public static bool operator false(EvilBool b)
{
throw new NotImplementedException();
}
public static implicit operator EvilBool(bool b) { return new EvilBool { value = b }; }
public static EvilBool operator|(EvilBool left, EvilBool right)
{
return left.Value || right.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment