Last active
July 12, 2023 19:51
-
-
Save zsmahi/8cc99f82930b6a553da38d4a471a79ff to your computer and use it in GitHub Desktop.
In<T> extension method for checking if an item is within a collection
This file contains 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.Linq; | |
using System.Collections.Generic; | |
public static class ExtensionMethods | |
{ | |
public static bool In<T>(this T item, IEqualityComparer<T> comparer, params T[] collection) | |
{ | |
if (!collection.Any()) | |
{ | |
return false; | |
} | |
return collection.Contains(item, comparer); | |
} | |
public static bool In<T>(this T item, params T[] collection) | |
{ | |
if (!collection.Any()) | |
{ | |
return false; | |
} | |
return collection.Contains(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment