Gordana Sretenovic

Gordana Sretenovic

  • 1.7k
  • 64
  • 1.1k

Accessing subclass properties

Nov 2 2013 3:36 PM
 

I have a base class called StockItem and one called EcoStockItem and a Plate subclass. EcoStockItem has a Juice object that is a subclass to EcoStockItem. In another class, I have the method AddItem (StockItem p). From the Form1 class should I send the StockItem item as a parameter to the method AddItem? I could not access the other property from subclasses. How should I do it? Create an object of StockItem to inherit all properties from subclasses and add it to a StockItem array?

            

 

 

newStockItem = new StockItem();

 

 

 

 

 

 

newStockItem.Id = id;

newStockItem.Name = name;

newStockItem.StockCount = stockcount;

newEcoStockItem =new EcoStockItem ();

 

 

 

newEcoStockItem.Markning = markning;

newPlate = new Plate();

 

 

 

 

 

newPlate.Typ = typ;

newJuice = new Juice();

 

 

 

 

 

newJuice.Typ = jtyp;

// StockItem p = ????

 

 

Stock stock = new Stock();

 

 

stock.AddItem(p);



 



 

and method: 

 

 

 

public StockItem[] StockItems = new StockItem[10];

 

 

public void AddItem(StockItem item)

 

 

{

int index = GetCount();

 

 

StockItems[index] = item;

Form1.myForm.textBoxTest.Text = StockItems[index].ToString();

 

 

}

 


 


Answers (1)