Dictionary Contains Key Ignoring Case - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

Dictionary Contains Key Ignoring Case

Demo Code


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

public class Main{
        public static bool DictionaryContainsKeyIgnoringCase(IDictionary<string, string> dictionary, string key)
        {
            if (dictionary.ContainsKey(key))
            {
                return true;
            }
            foreach (var f in dictionary.Keys)
            {
                if (String.Equals(f, key, StringComparison.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }
}

Related Tutorials