1
私は、この2つのタイプのパラメータ渡しの間に大きな混乱があります。どちらも同じように見えます。私はここで自分のコードを送信していますが、両方のメソッドが同じ機能を実行します。しかし、私はどちらがプログラミングにとって効果的な方法か分かりません。メソッド(Object sender、EventAgrs e)とメソッド(control c)のどちらが良いでしょうか?
public void remvuserpro(ListBox lb1)
{
string temp1 = "";
foreach (KeyValuePair<string, int> rm in purchase)
{
string temp=rm.Key+"\t"+rm.Value;
if (temp ==lb1.SelectedItem.ToString())
{
temp1 = rm.Key;
lb1.Items.Remove(lb1.SelectedItem);
billtotal -= rm.Value;
label3.Text = Convert.ToString(billtotal);
break;
}
}
purchase.Remove(temp1);
}
public void rmv(object sender, EventArgs e)
{
ListBox lb1 = sender as ListBox;
string temp1 = "";
foreach (KeyValuePair<string, int> rm in purchase)
{
string temp = rm.Key + "\t" + rm.Value;
if (temp == lb1.SelectedItem.ToString())
{
temp1 = rm.Key;
lb1.Items.Remove(lb1.SelectedItem);
}
}
purchase.Remove(temp1);
}
2番目のタイプはイベント用にのみ使用し、非イベントハンドラメソッド用には最初の特定のタイプを使用します。 –