[英]Stack in C# Form, proceed button for Push
我無法在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();
}
}
}
我不知道我應該聲明哪個函數,如何使繼續按鈕將數據推送到我的棧?
正如@ orhtej2在他的評論中指出的那樣,您應該將數據聲明為formpn
類的成員變量。 您也最好使用類型化的堆棧通用類型,並使用只讀聲明來使您清楚地知道以后不打算重新分配集合:
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)
{
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.