Collection Contains Ignoring Case - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Collection Contains Ignoring Case

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*from  w ww . j  a v a 2 s  .c  om*/

public class Main{
        public static bool CollectionContainsIgnoringCase(ICollection<string> collection, string val)
        {
             if (collection.Contains(val))
            {
                return true;
            }
            foreach (var f in collection)
            {
                if (String.Equals(f, val, StringComparison.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }
}

Related Tutorials