Skip to content

Instantly share code, notes, and snippets.

@jonsagara
Created May 3, 2012 20:02
Show Gist options
  • Save jonsagara/2588852 to your computer and use it in GitHub Desktop.
Save jonsagara/2588852 to your computer and use it in GitHub Desktop.
C# In() method
/// <summary>
/// Checks to see if source is in the items collection.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="items"></param>
/// <returns></returns>
public static bool In<T>(this T source, params T[] items)
{
if (items == null)
{
throw new ArgumentNullException("items");
}
return items.Contains(source);
}
/// <summary>
/// Checks to see if source is in the items collection.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="items"></param>
/// <returns></returns>
public static bool In<T>(this T source, IEnumerable<T> items)
{
if (items == null)
{
throw new ArgumentNullException("items");
}
return items.Contains(source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment