C# ArrayList Help - ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kinkay716
    New Member
    • Feb 2008
    • 1

    C# ArrayList Help - ASP.NET

    Hello -

    Im looking for some clarification on ArrayLists for a project I'm working on. It is basically a program which allows you to create a custom deck of cards. There is a listbox of available cards, the user selects a card and clicks add, which invokes a method to add to the arraylist.

    My AddCard onclick events looks something like the following:

    protected void add_Click(objec t sender, EventArgs e)
    {


    CustomDeck newCustomDeck;
    newCustomDeck = (CustomDeck)Ses sion["CurrentDec k"];


    Card newCard = new Card();

    newCard.Name = cardListBox.Sel ectedItem.Text;
    newCard.CardID = cardListBox.Sel ectedItem.Value ;

    newCustomDeck.A ddCard(newCard) ;

    Session["CurrentDec k"] = newCustomDeck;

    }

    - My AddCard Method looks like:

    //_newDeck is the ArrayList which is part of my CustomDeck domain class.
    public bool AddCard(Card card)
    {

    _newDeck.Add(ca rd);
    return true;

    }

    - So by my logic, when I instantiate a new card and add it into the arraylist, the arraylist will be full of different 'card' instances. How would I go about implementing the removeCard method? When i pass a card object into the arraylist, what is the handle of the card object? When I implement the removeCard method, Ill need some sort of handle to the proper card I want to remove...

    if i do the following:
    public bool RemoveCard(Card card)
    {

    _newDeck.Add(ca rd);
    return true;

    }

    How does the arraylist know which card I am referring to?

    Any help would be great!
    Thanks.
    Last edited by jhardman; Feb 19 '08, 10:07 PM. Reason: moved to .Net forum. ASP forum is for "classic" ASP
Working...