Search code examples
c#.netconstructor-chaining

Expression denotes a `variable', where a `method group' was expected


public class ItemStack
{
    public int stackSize;
    public int itemID;
    public int itemDamage;

    public ItemStack(Item item)
    {
        this(item.id, 1, 0); //ERROR HERE
    }

    public ItemStack(Item item, int value)
    {
        this(item.id, value, 0); //ERROR HERE
    }

    public ItemStack(Item item, int value, int value2)
    {
        this(item.id, value, value2); //ERROR HERE
    }

    public ItemStack(int value, int value2, int value3)
    {
        this.stackSize = 0;
        this.itemID = value;
        this.stackSize = value2;
        this.itemDamage = value3;

        if (this.itemDamage < 0)
        {
            this.itemDamage = 0;
        }
    }

    private ItemStack()
    {
        this.stackSize = 0;
    }
}

I don't know how solve this, if you have any idea please help me. Thanks. I don't have any idea how solve this, I tried differents ways but nothing. The errors are situated where you see "ERROR HERE" just these lines.


Solution

  • You're trying to chain constructors, that's not how you do that. You need call : this() in the constructor declaration:

    public ItemStack(Item item) : this(item.id, 1, 0)
    {
    }
    
    public ItemStack(Item item, int value) : this(item.id, value, 0)
    {
    }
    
    public ItemStack(Item item, int value, int value2) : this(item.id, value, value2)
    {
    }