can someone please help me... Im trying to display the items in the list on the console.
the current output is displaying my two sub classes: Grocery and FreshProduce. I have also added a image showing the current result below.
any help is much appreciated.
namespace ShoppingList
{
class ShoppingList
{
static void Main(string[] args)
{
Grocery myGrocery = new Grocery("Bread", 1);
FreshProduce myFreshProduce = new FreshProduce("Orange", 1);
List<object> myShoppingList = new List<object>();
myShoppingList.Add(myGrocery);
myShoppingList.Add(myFreshProduce);
PrintValues(myShoppingList, '\t');
}
public static void PrintValues(IEnumerable myList, char mySeparator)
{
foreach (Object obj in myList)
Console.Write("{0}{1}", mySeparator, obj);
Console.WriteLine();
}
public abstract class Product
{
protected string Name;
protected int Quantity;
}
public class Grocery : Product
{
public Grocery(string groceryName, int groceryQuantity)
{
Name = groceryName;
Quantity = groceryQuantity;
}
}
public class FreshProduce : Product
{
public FreshProduce(string freshProduceName, int freshProduceQuantity)
{
Name = freshProduceName;
Quantity = freshProduceQuantity;
}
}
}
}