Selecting an object from a listbox quickly
<p>I am trying to retrieve an object that is in an array when the user selects something in the listbox.</p>

<p>At the moment the listbox has a list of filenames and the way I have achieved the solution is by looping through the array and finding a matching filename and using the object reference once it has been found.</p>

<pre><code>foreach (CPSImage img in objWholeLibrary)
        {
            if (Path.GetFileName(img.FileName).Equals(lbxImageObjects.SelectedItem.ToString()))
            {
                currImage = img;
                break;
            }
        }
        UpdateDisplay();
</code></pre>

<p>Is there a more efficient way of doing this? Instead of relying on a string to match to the object?</p>
