Skip to content

Instantly share code, notes, and snippets.

@dchw
Created May 1, 2014 06:33
Show Gist options
  • Save dchw/9f20db3a3a5b3c419b7c to your computer and use it in GitHub Desktop.
Save dchw/9f20db3a3a5b3c419b7c to your computer and use it in GitHub Desktop.
Using the true/false overrides to easily choose people to marry.
void Main()
{
var boyfriends = new List<Boyfriend>
{
new Boyfriend
{
LovesMe = true,
LovesMeNot = false,
EntriesOnRapSheet = int.MaxValue,
Name = "Ima Baddude"
},
new Boyfriend
{
LovesMe = false,
LovesMeNot = true,
EntriesOnRapSheet = 0,
Name = "Itsnotyou Itsme"
},
new Boyfriend
{
LovesMe = true,
LovesMeNot = false,
EntriesOnRapSheet = 1,
Name = "Fox Mulder"
}
};
foreach (var marriageCandidate in boyfriends)
{
if(marriageCandidate)
{
Console.WriteLine(marriageCandidate);
}
}
}
public class Boyfriend
{
public bool LovesMe { get; set; }
public bool LovesMeNot { get; set; }
public int EntriesOnRapSheet { get; set; }
public string Name { get; set; }
public static bool operator true(Boyfriend boyfriend)
{
return boyfriend.LovesMe && !boyfriend.LovesMeNot && boyfriend.EntriesOnRapSheet < 5 && boyfriend.Name != "Rico Suave";
}
public static bool operator false(Boyfriend boyfriend)
{
//Simply return the opposite of whatever the true operator returns.
//So, if true return false, we return true here - which means "Yes, this is true." Got it?
return !(true);
}
public override string ToString()
{
return Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment