Hi everyone and thanks for your help! First I tell you the context. I have to do on a windows 8 universal app, a Drink Vending Machine Simulator. My classes are:
Manager (who creates the machine and puts in the ingredients and the drinks),
VendingMachine (who has the list of ingredients and drinks, checks if there is enough drinks left, etc.)
an Ingredient class with name and amount,
an abstract base class Drink with name, price, etc. and
classes Tea, Coffee and Chocolate who inherit from Drink and have own list of ingredient instances.
Now, when I select a drink in the machine, I'm checking every ingredient from it's name, if there is an ingredient with the same name on the machine I'm checking if there is left and I'm taking one.
The thing is, it should be easy to add a new type of Drink, but (!) if the name of the ingredient is not exactly the same it will not work. So I wanted to do an enum, I did it into the machine like:
public enum IngredientsNames
{
Coffee,
Tea,
Chocolate,
Sugar,
Milk
}
The ingredient class is:
class Ingredient
{
public string name { get; private set; }
public int amount;
public Ingredient(string _name)
{
name = _name;
}
}
But the problem is if I want to do in the vending machine class:
IngredientNames.Coffee = "Coffee" ;
It says
"The left hand side of an assignment must be a variable, proprety or indexer"
To be clear, I wanted that if someone opens a new class of type of drink, and does Ingredient.Coffee
it gives him automatically the string of the name "Coffee", he doesn't have to give the name himself, to not have an error after.
I hope I was clear. Thanks for your help I'm still beginning in this.