Skip to content

Instantly share code, notes, and snippets.

@mstrobel
Created July 26, 2012 05:56
Show Gist options
  • Save mstrobel/3180488 to your computer and use it in GitHub Desktop.
Save mstrobel/3180488 to your computer and use it in GitHub Desktop.
So much evil...
using System;
namespace Evil
{
internal static class Program
{
private static void Main(string[] args)
{
Evil x;
MoreEvil y;
// Prints True, False
Console.WriteLine(x == true ? true : false);
Console.WriteLine(x ? true : false);
// Prints False, True
Console.WriteLine(y == true ? true : false);
Console.WriteLine(y ? true : false);
}
}
public struct Evil
{
public static bool operator true(Evil x)
{
return false;
}
public static bool operator false(Evil x)
{
return true;
}
public static bool operator ==(Evil x, bool y)
{
return true;
}
public static bool operator !=(Evil x, bool y)
{
return false;
}
}
public struct MoreEvil
{
public static Evil operator ==(MoreEvil x, bool y)
{
return default(Evil);
}
public static Evil operator !=(MoreEvil x, bool y)
{
return default(Evil);
}
public static bool operator true(MoreEvil x)
{
return true;
}
public static bool operator false(MoreEvil x)
{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment