Using the IComparer<string> class:
public class CaseInsensitiveComp: IComparer<string> { private CaseInsensitiveComparer _comp = new CaseInsensitiveComparer(); public int Compare(string x, string y) { return _comp.Compare(x, y); } }
Then do BinarySearch in the array sorted :
var myKeys = new List<string>(){"boot", "FOOT", "rOOt"}; IComparer<string> comp = new CaseInsensitiveComp(); myKeys.Sort(comp); int theIndex = myKeys.BinarySearch("foot", comp);
Usually most effective for large arrays, preferably static.
source share