Skip to content

Instantly share code, notes, and snippets.

@gowon
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save gowon/403156a04a4d97617c8a to your computer and use it in GitHub Desktop.

Select an option

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
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());
}
}
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