Dictionary Get Value Ignoring Case - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

Dictionary Get Value Ignoring Case

Demo Code


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

public class Main{
        public static string DictionaryGetValueIgnoringCase(IDictionary<string, string> dictionary, string key)
        {
            if (dictionary.ContainsKey(key))
            {
                return dictionary[key];
            }
            foreach (var f in dictionary.Keys)
            {
                if (String.Equals(f, key, StringComparison.InvariantCultureIgnoreCase))
                {
                    return dictionary[f];
                }
            }
            return null;
        }
}

Related Tutorials