Created
May 1, 2014 06:33
-
-
Save dchw/9f20db3a3a5b3c419b7c to your computer and use it in GitHub Desktop.
Using the true/false overrides to easily choose people to marry.
This file contains hidden or 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
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