British Inside

An Englishman living in small town America

James Shaw

News

  • Copyright James Shaw 2004-2007

    Creative Commons License

    View James Shaw's profile on LinkedIn

Contains > IndexOf

Newbie tip. This is good: 

if (error.Contains("Declined"))..

Not so much:

if (error.IndexOf("Declined") != -1)..

Guess which seems to be more common in code Stick out tongue 

P.S. Yes, I have old code with examples of the latter. Doesn't count.


 

Posted: Saturday, March 15, 2008 6:14 PM by James
Filed under: ,

Comments

Ken Robertson said:

string.Contains() was new in .NET 2.0, so a lot of people were (and still are) hooked on the old .NET 1.1 way. :) Same with string.IsNullOrEmpty().
# March 15, 2008 10:23 PM
New Comments to this post are disabled