Attention: We are retiring the ASP.NET Community Blogs. Learn more >

System.Collections.Specialized.StringCollection

I needed a type that could handle an array of strings who's size I never knew.  The StringCollection type handles this very well and has some handy methods for looking into the collection.

For example, in my case I am looping through all of the datacolumns in a datarow.  As I discover a modifed column, I add the ColumnName to the StringCollection.  Later, I look inside the StringCollection to see if I have already built a SqlParameter type for the modified column.  I do this when building the primary key columns.  If the primary key was modified, I do not want to build another SqlParameter as it was already build in the first loop.

I look into the StringCollection like this:

If Not ColumnsModifed.Contains(col.ColumnName.ToString) Then

where ColumnsModified is my StringCollection and col.ColumnName.ToString is my primary key column.  I was going to use an ArrayList, however this type is not Strongly Typed and requires boxing and unboxing. .

   

2 Comments

Comments have been disabled for this content.