Skip to content

Instantly share code, notes, and snippets.

@zsmahi
Last active July 12, 2023 19:51
Show Gist options
  • Save zsmahi/8cc99f82930b6a553da38d4a471a79ff to your computer and use it in GitHub Desktop.
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
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