Going back with a Vengeance So I received a comment on my previous question that suggested creating a Dictionary of my menus to store the data in.  So that got me thinking, all I am doing is going back to the first instance of MenuItem in the ItemList that has a Menu of Back[0].Menu.  So why not just iterate through there and open the menu when I find it?

So, here is my final code:



public void GoBack()
{
    NavButtonUsed = true;

    Forward.Insert(0, Back[0]);
    Back.RemoveAt(0);

    if (Back[0].Title.StartsWith(" ") &amp;&amp; CurrentItem.Menu != Back[0].Menu)
    {
        foreach(MenuItem mi in ItemList)
        {
            if (mi.Menu == Back[0].Menu)
            {
                CurrentItem = ItemList[ItemList.IndexOf(mi)];
                break;
            }
        }
    }

    CurrentItem = ItemList[ItemList.IndexOf(Back[0])];
    NavButtonUsed = false;
}


Everything else stayed the same as in my previous question, please check that for details.
CurrentItem = ItemList[ItemList.IndexOf(mi)];


can just be

CurrentItem = mi;


You could also use FirstOrDefault:

var item = ItemList.FirstOrDefault(i =&gt; i.Menu == Back[0].Menu);
if (item != null)
{
    CurrentItem = item;
}