摘要:(200-07-23) LINQ Delegate(委派)
定義泛型委派
//定義委派
namespace util
{
//傳遞兩個類型進行整理
public delegate void calNumber<T>(T v1,T v2); // T 為泛型
}使用泛型委派
private void button4_Click(object sender, EventArgs e)
{
//建構委派
util.calNumber<Int32> handler = new util.calNumber<int>(cal);
handler(100, 200);
//建構委派
util.calNumber<String> handler2 = new util.calNumber<string>(concatString);
handler2("eric"," Linda");
}
//整數計算
private void cal(Int32 i1, Int32 i2)
{
MessageBox.Show((i1 + i2).ToString());
}
//字串串連
public void concatString(String s1, String s2)
{
MessageBox.Show((s1 + s2));
}