Acces to list in Form1 without creating a new instance
I'm currently working on a calculator with reverse polish notation to learn about stacks, abstract classes, inheritance etc. I get a stackoverflow error when i try to inherit from Form1 in my abstract class.
The question is: Is there a way to prevent this error from happening and get acces to two lists in my Form1? When i use Form1 form1 = new Form1();
I create a new instance of Form1, and the result is an empty list, so i was thinking about inheriting Form1.
I inherit from this class, because I'm trying to reach this two lists in my Form 1:
In the Form1 class i've got 2 lists:
public List<string> lastEventList = new List<string>();
public List<string> stackDisplayList = new List<string>();
This is my abstract class:
abstract class Stack : Form1
{
ListBox lastEvent, stackDisplay;
public Stack() { }
public Stack(ListBox lastEvent, ListBox stackDisplay)
{
this.lastEvent = lastEvent;
this.stackDisplay = stackDisplay;
}
public abstract int Pop();
public virtual void Push(int i)
{
//how to acces list
lastEventList.Add("Pushed " + i + " on stack");
((CurrencyManager)lastEvent.BindingContext[lastEventList]).Refresh();
string addItem = String.Format("[{0}] \t -> \t {1}", 11 - Count(), i);
stackDisplayList.Add(addItem);
((CurrencyManager)stackDisplay.BindingContext[stackDisplayList]).Refresh();
}
public abstract int Count();
}
Do you know how to prevent the stackoverflow error and get acces to those lists?
Aucun commentaire:
Enregistrer un commentaire