Friday, February 12, 2010

Programmer - Using InvariantCultureIgnoreCase instead of ToUpper for case-insensitive string comparisons

On this page, a commenter writes:



Do NOT ever use .ToUpper to insure comparing strings is case-insensitive.



Instead of this:



type.Name.ToUpper() == (controllerName.ToUpper() + "Controller".ToUpper())) 


Do this:



type.Name.Equals(controllerName + "Controller", 
StringComparison.InvariantCultureIgnoreCase)


Why is this way preferred?

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails