ขั้นแรกก็เพียงประกาศ delegate เอาไว้...
ผมแปะโค๊ดไว้ก่อน เดี๋ยวมาอธิบายทีหลัง ตอนนี้ ไม่ว่าง ฮ่าๆๆ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SampleDay1
{
public class Program4
{
public static void Main(string[] args)
{
Person person1 = new Person() { name = "Sam" };
Person person2 = new Person() { name = "Lula" };
Person person3 = new Person() { name = "Billy" };
Animals animal1 = new Animals() { name = "Dog" };
Home home = new Home();
home.OnFired += person1.PersonFired;
home.OnFired += person2.PersonFired;
home.OnFired += person3.PersonFired;
home.OnFired += animal1.Bank;
home.Fire();
Func<int,int> fu = new Func<int,int>(DoSong);
int result = fu.Invoke(2);
Console.ReadLine();
}
public static int DoSong(int u)
{
Console.WriteLine("sdfdsf");
return 1;
}
}
public class Home
{
public string color;
public int height;
public int width;
public event OnFireHandler OnFired;
public void Fire()
{
string ss = "h";
if (OnFired != null)
{
OnFired(ss);
}
}
public void build(string chars)
{
Console.WriteLine("CH :" + chars);
}
}
public class Person
{
public string name;
public string PersonFired(string x)
{
Console.WriteLine(name + " said fire fire fire!!!"+ x);
return null;
}
}
public partial class Animals
{
public string name;
public string Bank(string xx)
{ Console.WriteLine(name + "said Bank Bank Bank!!!" + xx); return null; }
}
public delegate string OnFireHandler(string str);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น