String comparison

Strings has always been my favourite topic and given the shance i can keep talking about them for hours.

In this string comparison has been my favourite, because every develope at one time or another needs to perform String comparison and most of the times does it the wrong way.

During my code reviews this the item which have seen maximum times,

if(textbox1.Text.Trim().ToLower() == "ABC")
//Do Something

I can bet maximum number of people make this mistake without realizing that they have just created an extra string object and added to the workload of GC.

The better approach for doing this is use inbuild compare method.



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: