WebApr 25, 2016 · If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome. Don't tell someone to read … WebJul 15, 2010 · C# IEqualityComparer customComparer = new PropertyComparer ( "Name" ); IEnumerable distinctEmails = collection.Distinct (customComparer); Enhancements Currently, this implementation only works for public properties on a class. It would be easy to extend it to also inspect public …
c# - How to compare Dictionary values ignoring case - Stack Overflow
WebJan 21, 2024 · In the case of String.Equals, a StringComparison argument can be provided to alter its sorting rules. The following example demonstrates that: C# string root = @"C:\users"; string root2 = @"C:\Users"; bool result = root.Equals (root2); Console.WriteLine ($"Ordinal comparison: <{root}> and <{root2}> are { (result ? "equal." WebJul 20, 2024 · The HashSet constructor has an overload that lets you pass in a custom IEqualityComparer. There are a few of these defined for you already in the static StringComparer class, a few of which ignore case. For example: var set = new HashSet (StringComparer.OrdinalIgnoreCase); set. Add ("john"); Debug. chris lawrence ice hockey
Comparing two strings, ignoring case in C# - Stack Overflow
WebJun 23, 2011 · It will fail if you have two objects of type A with three properties as shown below: Objects: object 1 { prop1 = B, prop2 = C, prop3 = B } object 2 { prop1 = B, prop2 = … WebNov 14, 2024 · For better performance with structs there isn't any boxing. Usage is like this: IEqualityComparer equalityComparer = KeyBasedEqualityComparer.Create (x => x.Numf); Share. Improve this answer. Follow. edited May 7, 2024 at 8:25. answered Sep 30, 2024 at 9:59. user764754. WebSep 27, 2013 · 4 Answers. Sorted by: 2. Order by the key, select the value and use the overload of SequenceEqual with StringComparer.OrdinalIgnoreCase: bool areEqual = dic1.OrderBy (x => x.Key).Select (kv => kv.Value) .SequenceEqual (dic2.OrderBy (x => x.Key).Select (kv => kv.Value), StringComparer.OrdinalIgnoreCase); chris lawrenson