Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I convert a string to upper case when comparing?

Tags:

c#

I constantly read about it being a good practise to convert a string to upper case (I think Hanselman mentioned this on his blog a long time ago), when that string is to be compared against another (which should also be converted to upper case).

What is the benefit of this? Why should I do this (or are there any cases when I shouldn't)?

Thanks

like image 363
gss3 Avatar asked Feb 11 '26 16:02

gss3


1 Answers

no, you should be using the enum option that allows for case insenstive comparisson (string comparison).

Make sure to use that overload of the comparison method you are using i.e. String.Compare, String.Equals

like image 62
eglasius Avatar answered Feb 14 '26 14:02

eglasius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!