The type (my class) must be a non-empty type for use as the "T" parameter in the general method

So, I enjoy the compiler! I will also add it here: "The type (my class) must be non-empty in order to use it as the" T "parameter in the general method"

This does not make sense to me since my method is not general. This is how I call offensive code:

Item? inputtedItem = SearchProduct(txtProduct.Text);

Meanwhile, here is the definition of 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 instance if it appears in the inventory.  Otherwise return null.
        return _inventory[product];
    }

I believe that I will add an indexer from my inventory class here for a good estimate:

       public Item this[string i]
    {
        get
        {
            Item returnItem;
            _productList.TryGetValue(i, out returnItem);
            return returnItem;
        }
        set
        {
            _productList.Add(i, value);
        }
    }

Does anyone know what happened?

Thanks for the help.

+5
source share
1 answer

, ? Item?. Item - , NULL.

+6

All Articles