Link to home
Start Free TrialLog in
Avatar of ToolTimeGang
ToolTimeGangFlag for United States of America

asked on

Case sensitivity difference between .NET 2.0 and 4.0

x = "Test"
If x = "test"
    do abc
Else
    do efg
End if

I have proven the above code works differently between my .NET 2.0 and .NET 4.0 console apps.
.NET 2.0 console app will execute abc.  
.NET 4.0 console app will execute efg.

Why doesn't the 2.0 app do the same thing as the 4.0 app?  Is there a configuration that says to not worry about case sensitivity or something?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ToolTimeGang

ASKER

Bingo.  The 2.0 app had Option Compare = Text instead of binary.
I changed it, and the code is executing like the 4.0 code.
thanks for your prompt response!
You rock for getting back to me so quickly.  This was driving me nuts!  Thank you!
Not a problem ToolTimeGang, glad I was able to help. Have a great day.
Actually, although it solved your problem, the information given by Fernando is not quite complete.

Option Compare Binary compare the binary values of the characters, their Unicode value, which makes it both Case and accent sensitive. The results are thus the same no matter the system on which it runs.

Option Compare Text follows the language specified in the Control Panel, and will thus change depending on the language. Most languages are case insensitive, but many are sensitive to accents. The results might thus be different from one computer to another.

The best way to compare strings is to use the String.Compare method. It has overloads that let you specify the case sensitivity and the language to use for everything else, so it is the only way to be assured of always getting the same results in a given application.
Awesome.  That is exactly what I ended up coding yesterday:

...If String.Compare(msgType, "event", True) = 0 Then...

Thank you so much for taking the time to make that point even after the entry was closed.  That shows you care.  Have a great Thanksgiving!