kamagra how much to take

Why CommaDelimitedStringCollection Made Me Happy Today

Another thing that I stumbled on today that has made me all sorts of happy is the CommaDelimitedStringCollection class, which basically let’s you take a bunch of string values and work with them in a comma delimited format (so I guess the class name is pretty intuitive :) ). I can’t even explain how many times I have re-invented this wheel. So let’s say that you have a ListBox control that contains a set of string type values, and you are adding the selected values to a list generic in something like an event handler, you would have this basically:

  1. List<String> m_gBoxGeneric = new List<String>();
  2. foreach (string l_strValue in l_oTbExample.SelectedItems)
  3. {
  4. m_gBoxGeneric.Add(l_strValue);
  5. }

where the l_oTbExample is just a ListBox control. This isn’t very earthshattering and I am just using that loop as an example. Now, let’s say you want to output those selected values into a comma delimited format. The easiest way to do it is to just use the CommaDelimitedStringCollection class, which natively provides this functionality. It would look like this:

  1. CommaDelimitedStringCollection m_oDelimitedFormat = new CommaDelimitedStringCollection();
  2.  
  3. List<String>.Enumerator l_oEnumerator = m_gBoxGeneric.GetEnumerator();
  4. try
  5. {
  6. while (l_oEnumerator.MoveNext())
  7. {
  8. string l_strBoxVal = l_oEnumerator.Current;
  9. m_oDelimitedFormat .Add(l_strBoxVal);
  10. }
  11. }
  12. finally
  13. {
  14. l_oEnumerator.Dispose();
  15. }

Then you can just output the comma delimited values by doing a m_oDelimitedFormat.ToString() and you are done!

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>