【问题标题】:Expression denotes a `variable', where a `method group' was expected表达式表示一个“变量”,其中需要一个“方法组”
【发布时间】:2015-07-24 01:00:37
【问题描述】:
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;
    }
}

我不知道如何解决这个问题,如果您有任何想法,请帮助我。谢谢。 我不知道如何解决这个问题,我尝试了不同的方法但没有。错误位于您仅在这些行中看到“ERROR HERE”的位置。

【问题讨论】:

    标签: c# .net constructor-chaining


    【解决方案1】:

    您正在尝试链接构​​造函数,这不是您这样做的方式。您需要在构造函数声明中调用: this()

    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)
    {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      • 2019-07-12
      • 1970-01-01
      相关资源
      最近更新 更多