Created
February 13, 2012 20:11
-
-
Save mgroves/1819784 to your computer and use it in GitHub Desktop.
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
| // better like this? | |
| var isMyFavoriteLetter = new List<string> { "A", "B", "C"}.Contains(myFavoriteLetter); | |
| // or better like this? | |
| var isMyFavoriteLetter = myFavoriteLetter == "A" || myFavoriteLetter == "B" || myFavoriteLetter == "C"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer:
myFavoriteLetter.IsIn("A", "B", "C").
IsIn() is easy to write:
public static bool IsIn(this T p_value, params T[] p_list) {
return p_value.IsIn(p_list.ToList());
}
public static bool IsIn(this T p_value, IList p_list) {
if (p_list == null || p_list.Count == 0)
return false;
}