Look at your code:
public string foodRemover { get; set; }
...
List<food<string>> foodstring = new List<food<string>>();
foodRemover = Console.ReadLine();
if(foodstring.Contains(foodRemover))
foodRemover
is a
string
;
foodstring
is a collection of
food
instances.
So when you try to call
Contains
, the system tries to find a way to cast the
string
to a
food
and does not find any implicit converter and throws the error. It will do the same for your
cleaner
code.
That whole code looks like you don't really understand classes and inheritance very well yet - it can't work the way you are trying to do it because your
Product
class is trying to derive from both the
Food
and
Cleaner
classes, and that's wrong - C# will not allow you to derive from more than one base class.
Even if it could, you are saying that a
Product
is both a
Food
and a
Cleaner
, rather than a
Cleaner
is a
Product
; and a
Food
is a product.
In real sword terms, that's is saying that this single piece of fruit in my hand is both an Apple and a Bicycle because Walmart sell both items!
Product
is the base class: both
Food
and
Cleaner
should derive from that.
Make a copy of that code so you can look back on it in a few weeks time, then throw it all away - it's fundamentally wrong, and none of it is worth keeping.
Then go back to your course notes and read up on classes and inheritance again before re-reading your assignment. You need to work out exactly what you are doing before you leap into code!