I only recently came across Option Compare Text
in a roundabout fashion. We have all sorts of:
soAndSo.Equals("one", StringComparison.CurrentCultureIgnoreCase)
and it seemed the option would be useful. However, many of those comparisons are in the keys of dictionaries, so I did this…
Option Compare Text
'Option Compare Binary
Dim testdict As New Dictionary(Of String, String)
testdict.Add("OneTwo", "onetwo")
testdict.Add("TwoThree", "twothree")
testdict.Add("ThreeFour", "threefour")
If "one" = "One" Then
Dim y As Integer = 5
End If
If testdict.ContainsKey("onetwo") Then
Dim y As Integer = 5
End If
If testdict.ContainsValue("OneTwo") Then
Dim y As Integer = 5
End If
If testdict.ContainsValue("onetwo") Then
Dim y As Integer = 5
End If
And that does not work, changing the Option has no effect, neither the dictionary keys or values match. I was surprised by this, as it seems MS is not using their own blessed equality tests.
I know I can make a dictionary with a different comparison operation, but I’m wondering if I’ve simply missed some equally simple switch? Google says no, but I don’t trust google any more.