Last active
August 29, 2015 14:22
-
-
Save gowon/403156a04a4d97617c8a to your computer and use it in GitHub Desktop.
Fairly elegant & performant way to find if object is contained in set without using Linq
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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| public static class GenericExtensions | |
| { | |
| public static bool IsElementOf<T>(this T item, params T[] list) | |
| { | |
| return Array.IndexOf(list, item) != -1; | |
| } | |
| public static bool IsElementOf<T>(this T item, IEnumerable<T> list) | |
| { | |
| return IsElementOf(item, list.ToArray()); | |
| } | |
| } |
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
| using System; | |
| public static class GenericExtensions | |
| { | |
| public static bool IsElementOf<T>(this T item, params T[] list) | |
| { | |
| return Array.IndexOf(list, item) != -1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment