Skip to content

Instantly share code, notes, and snippets.

@caseywatson
Last active August 29, 2015 14:17
Show Gist options
  • Save caseywatson/af1e24efaa4faa0e25b7 to your computer and use it in GitHub Desktop.
Save caseywatson/af1e24efaa4faa0e25b7 to your computer and use it in GitHub Desktop.
OnlyOne Extension Method
public static bool OnlyOne<T>(this IEnumerable<T> source, Func<T, bool> condition = null)
{
return (source.Count(condition ?? (t => true)) == 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment