我无法在C#Form应用程序中实现堆栈和查询。
我的代码看起来像这样。
namespace Program_Pajak
{
public partial class formppn : Form
{
public formppn()
{
InitializeComponent();
}
private void formppn_Load(object sender, EventArgs e)//kinda confused, placing stack in which function
{
Stack sit = new Stack();
Stack sht = new Stack();
int count1 = sit.Count;
int count2 = sht.Count;
}
private void button1_Click(object sender, EventArgs e) //this is proceed button for Push stack
{
sit.Push(item);
si.Text = count1.ToString();
}
}
}
我不知道应该在哪个函数中声明我的堆栈,以及如何使用继续按钮将数据推送到堆栈中?
答案 0 :(得分:0)
正如@ orhtej2在他的评论中指出的那样,你应该将你的数据声明为formpn
类的成员变量。您最好使用键入的generic version of stack并使用readonly声明来明确表示您以后不会重新分配集合:
namespace Program_Pajak
{
public partial class formppn : Form
{
Stack sit = new Stack();
Stack sht = new Stack();
public formppn()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void formppn_Load(object sender, EventArgs e)//kinda confused, placing stack in which function
{
int count1 = sit.Count;
int count2 = sht.Count;
}
private void button1_Click(object sender, EventArgs e) //this is proceed button for Push stack
{
sit.Push(item);
si.Text = count1.ToString();
}
private void si_Click(object sender, EventArgs e)
{
}
}
}