Skip to content

Instantly share code, notes, and snippets.

@Olwaro
Last active December 14, 2015 09:09
Show Gist options
  • Save Olwaro/5063283 to your computer and use it in GitHub Desktop.
Save Olwaro/5063283 to your computer and use it in GitHub Desktop.
C# extension method that emulate SQL's IN (...).
public static class Extensions
{
public static bool In<T>(this T obj, params T[] others) where T : IEquatable<T>
{
bool res = false;
for (int i = 0; i < others.Length; i++)
{
if (obj.Equals(others[i]))
{
res = true;
break;
}
}
return res;
}
}
@Olwaro
Copy link
Author

Olwaro commented Mar 15, 2013

Now restricted to types which implement IEquatable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment