我不想重複這個代碼的所有時間:如何不重複代碼? Xamarin - 安卓
Button btnClicks = FindViewById<Button>(Resource.Id.MyButton);
Button btnWarning = FindViewById<Button>(Resource.Id.ButtonWarning);
我怎樣才能改善這種代碼看起來更乾淨? 這段代碼的垃圾郵件真的會影響應用程序的性能嗎?
protected override void OnResume()
{
base.OnResume();
Button btnClicks = FindViewById<Button>(Resource.Id.MyButton);
Button btnWarning = FindViewById<Button>(Resource.Id.ButtonWarning);
btnWarning.Click += btnWarn;
}
protected override void OnPause()
{
base.OnPause();
Button btnClicks = FindViewById<Button>(Resource.Id.MyButton);
Button btnWarning = FindViewById<Button>(Resource.Id.ButtonWarning);
btnWarning.Click -= btnWarn;
}
private void btnWarn(object sender, EventArgs e)
{
Button btnWarning = FindViewById<Button>(Resource.Id.ButtonWarning);
btnWarning.Text = string.Format("Warning Test");
}
使用類的扣件和初始化在OnCreate然後經過再利用呢? – Kariem
使用成員變量/字段? –