check if the string is equals with any of the compare string. - CSharp System

CSharp examples for System:String Parse

Description

check if the string is equals with any of the compare string.

Demo Code


using System.Xml;
using System.Web;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  ww  w . j  a  v  a  2s . c  o  m*/

public class Main{
        /// <summary>
        /// check if the string is equals with any of the compare string.
        /// </summary>
        /// <param name="theSource">the source string</param>
        /// <param name="comparison">comparison type</param>
        /// <param name="compares">caompare strings</param>
        /// <returns>true or false</returns>
        public static bool EqualsAny(this string theSource, StringComparison comparison, params string[] compares)
        {
            return compares.Any(s => string.Equals(theSource, s, comparison));
        }
        /// <summary>
        /// check if the string is equals with any of the compare string.
        /// </summary>
        /// <param name="theSource">the source string</param>
        /// <param name="compares">caompare strings</param>
        /// <returns>true or false</returns>
        public static bool EqualsAny(this string theSource, params string[] compares)
        {
            return compares.Any(s => string.Equals(theSource, s));
        }
}

Related Tutorials