-1

I am trying to create a menu system and i am storing the menus in stacks once they have already been visited. Im trying to use Stack.Peek() to basically say: if menuName = menuStack.Peek, then continue.

menus have a drawRectangle, sprite, and Menuname enumeration associated with them, and all menus are child classes of the Menu class.

    public static void GoToMenu(MenuName menuName)
    {
        Stack<Menu> menuStack = new Stack<Menu>();
        Stack<Menu> tempStack = new Stack<Menu>();
        if(menuStack.Peek() = MainMenu){

        }
    }

More or less, if menuStack.Peek returns a mainMenu object. How do i check that?

i just really dont know how to read menuStack.Peek(). I dont know how to apply it to an if statement to check if it equals a mainmenu object, a pausemenu object or whatever.

user1801067
  • 133
  • 2
  • 12

1 Answers1

1
    public static void GoToMenu(MenuName menuName)
    {
        Stack<Menu> menuStack = new Stack<Menu>();
        Stack<Menu> tempStack = new Stack<Menu>();
        if(menuStack.Peek().Name == menuName){
            menuStack.Pop();
        }
    }

that is what i needed

user1801067
  • 133
  • 2
  • 12
  • This is how you determine if an object is an instance of a type. That is just one of an infinite number of possible ways you could compare objects, and it can be done inside or outside of an `if` statement. – Servy Nov 04 '14 at 19:22
  • so another quick question, using that i am able to check if the top object on my stack is of type MainMenu, but how would i make it check all menus but if they had the field MenuName = mainMenu? Remember i have mainmenu, difficultymenu, pausemenu all child classes of Menu – user1801067 Nov 04 '14 at 19:23
  • nvm, figured it out =) – user1801067 Nov 04 '14 at 19:24