Emad's Blog

Thoughts/Tips/Shortcuts/Ideas from a .NET software engineer

Archive for February, 2007

SQL Server 2005 SP2

Posted by emadmagdy on February 22, 2007

 

Service Pack 2 is released for SQL server 2005.

It is available Here

Posted in Uncategorized | Leave a Comment »

Google Code Search

Posted by emadmagdy on February 7, 2007

Google launched a new service to search for source Code. It is part of google labs.

http://www.google.com/codesearch

Posted in Uncategorized | Leave a Comment »

Note about the "foreach" enumeration

Posted by emadmagdy on February 1, 2007

 

There is a subtle note about using the “foreach” enumeration. The “foreach” uses an enumerator that assumes that the number of elements in the collection will remain intact during the enumeration.

If this changes, an exception “Collection was modified, Enumeration Operation may not execute”.

 

what that means is:

you can NOT do something like

foreach(datarow row in table.rows)

{

if (some condition)

{

     table.rows.remove(row);

}

 

trying to remove a row form within the enumeration will throw an exception.

 

 

A better way to do it is :

 

for(int x =  table.rows.count-1; x>=0; x– )

{

if (some condition)

{

     table.rows.remove(row);

}

Note that the for loop is a decrementing loop (x–) to avoid having problems with the rows position when one or more rows are removed from the collection

Posted in Uncategorized | Leave a Comment »