RiderJon
RiderJon

Reputation: 77

Using an other class as a parameter for a class

I'm creating a bool method called 'AddItem'. I am meant to use a class I create on a separate .cs called 'Item'. I need to use 'Item' as a parameter for 'AddItem' like this:

public bool AddItem(Item)
        {
            if (mItems == null)
                return true;
            else
                return false;
        }

The problem I am running into is an error saying 'Identifier expected' after the 'Item' parameter. However, when I say:

public bool AddItem(bool Item)
            {
                if (mItems == null)
                    return true;
                else
                    return false;
            }

It makes 'Item' a value and not a reference to my class.

Upvotes: 0

Views: 32

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416121

You have to give your item a name:

public bool AddItem(Item myItem)
{
    return myItem == null;
}

Upvotes: 3

Related Questions