title: Using Linq To Convert ListBox Items Values to int
body: <p>I display the contents of a table in the database using a ListBox. Each listbox item is populated with the Text property set to a friendly name, and the Value property set to the unique ID column. The database structure might look similar to the following:</p>
  
  <pre><code>CREATE TABLE GENERIC { FRIENDLY_NAME TEXT, ID INT }
  </code></pre>
  
  <p>I tried for almost an hour to convert the items of the listbox to an int[] using LINQ and ultimately failed. It is also important to distinguish between the selected and not selected items. Here is what i ended up writing:</p>
  
  <pre><code>System.Collections.Generic.LinkedList&lt;int&gt; 
              selected = new LinkedList&lt;int&gt;(), 
              notSelected = new LinkedList&lt;int&gt;();
  
          foreach (ListItem item in PhotoGalleryEdit_PhotoShoots.Items)
          {
              if (item.Selected)
                  selected.AddFirst(Convert.ToInt32(item.Value));
              else
                  notSelected.AddFirst(Convert.ToInt32(item.Value));
          }
  
   int []arraySelected = selected.ToArray();
   int []arrayNotSelected = notSelected.ToArray();
  </code></pre>
  
  <p>Can anyone show how this is done in LINQ?</p>
  
  <p><em>(I write all my code in C# but any answers written in VB would be more than welcome)</em></p>