yüzden eğlenceli bir derleyici hatası alıyorum genel yöntemde bir parametre 'T' olarak kullanmak için NULL olmayan türde olmalıdır! Ben de burada yapıştırın: "tür (benim sınıf) genel yöntem" T "olarak kullanmak için non-nullable tip olmalıdır"tipi (benim sınıfı)
Bu bana mantıklı gelmiyor Benim yöntemim genel olmadığından. İşte söz konusu kodu arıyorum nasıl:
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];
}
Ben iyi ölçmek için burada benim envanter sınıfından indeksleyiciyi ekleyeceğiz varsayalım: Bu arada
Item? inputtedItem = SearchProduct(txtProduct.Text);
, burada SearchProduct tanımıdır :
public Item this[string i]
{
get
{
Item returnItem;
_productList.TryGetValue(i, out returnItem);
return returnItem;
}
set
{
_productList.Add(i, value);
}
}
Herkes neyin yanlış olduğunu biliyor mu?
yardım için teşekkür ederiz.
'Item' bir' struct' mı? – dtb
'SearchProduct' bir arayüz yönteminin bir uygulaması mıdır? 'Item' girdiğiniz jenerik parametre 'T' olan bir arayüz? – Virtlink
Ben TryGetValue sizin genel yöntem olduğunu düşünüyorum. Tam olarak _productList türü nedir? –