IndexOf , , ListOfMyObjects , myListBox.Items, IndexOf .
, linq. , #, :
var items = from x in myListBox.Items where otherListOfMyObjects.Any(y => y == x ) select x;
foreach(item i in items)
myListBox.SelectedItems.Add(i);
Obviously this will not work, since y == x will always return false (so your current method will not work). You need to substitute y == x to perform an equality comparison, which will determine the equality as you define it for MyObject. You can do this by adding the identifier suggested by Fallen, or by overriding the methods suggested by Neal (+ s for both of them), or simply by defining which properties of MyObject need to be checked to identify them as exactly the same object.
source
share