You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotNetAdvcdGrammer/AnonymousMethod/DelegateTypeVsAnonymousMeth...

45 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnonymousMethod
{
class DelegateTypeVsAnonymousMethod : Form
{
// Delegate 타입
public delegate int SumDelegate(int a, int b);
public DelegateTypeVsAnonymousMethod()
{
// Delegate 사용
SumDelegate sumDel = new SumDelegate(MySum);
int result = sumDel(1, 2);
// 무명메서드1
this.Click += new EventHandler(delegate(object sender, EventArgs e)
{
MessageBox.Show("Way1");
});
// 무명메서드2
this.Click += (EventHandler)delegate(object sender, EventArgs e)
{
MessageBox.Show("Way2");
};
// 무명메서드3
this.Click += delegate
{
MessageBox.Show("Way3");
};
}
private int MySum(int a, int b)
{
return 0;
}
}
}