« a couple of useful tools | Main | Christmas at the Bergers' »
December 07, 2003
efficient empty string check
This is what I normally do and it is bad (not the best performance-wise)
foreach (string s in someCollection)
{
if (s != "")
{
...
}
}
And this is bad because it creates a new instance of an empty string every time through the loop. The more efficient way is to do this
foreach (string s in someCollection)
{
if (s.Length != 0)
{
...
}
}
via MSDN TV
Posted by mikel at December 7, 2003 02:29 PM
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)