Nic*_*ick 5 c# compiler-construction
所以我得到了一个有趣的编译器错误!我也会在这里粘贴它:"类型(我的类)必须是非可空类型才能在泛型方法中用作参数'T'"
这对我来说没有意义,因为我的方法不通用.以下是我如何调用违规代码:
Item? inputtedItem = SearchProduct(txtProduct.Text);
同时,这是SearchProduct的定义:
        private Item? SearchProduct(string product)
    {
        //If this is the first item to be entered into the inventory
        if (_inventory == null || _inventory._productList.Count == 0)
        {
            return null;
        }
        //Return the Item's instance if it appears in the inventory.  Otherwise return null.
        return _inventory[product];
    }
我想我会在这里添加我的库存类中的索引器以获得良好的衡量标准:
       public Item this[string i]
    {
        get
        {
            Item returnItem;
            _productList.TryGetValue(i, out returnItem);
            return returnItem;
        }
        set
        {
            _productList.Add(i, value);
        }
    }
有人知道什么是错的吗?
感谢您的帮助.
| 归档时间: | 
 | 
| 查看次数: | 4432 次 | 
| 最近记录: |