C# extension method to check if a string matches any string in given list

2016-06-16

/// <summary>
/// Note: this uses ordinal comparison
/// </summary>
/// <param name="?"></param>
/// <param name="Options"></param>
/// <param name="ignoreCase"></param>
/// <returns></returns>
public static bool IsOneOf(this string source, IEnumerable<string> Options, bool ignoreCase = false)
{
   return Options.Contains(source, ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
}

 
This entry was posted in C#.Net and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *