public static void Call() { SayHi del = EnglishSayHi; del("李四"); Test("张三", chineseSayHi); }
static void Main(string[] args) { WorkflowEngine workflowEngine = new WorkflowEngine(); UpLoadVideo activity = new UpLoadVideo(); SayHi sayHi = new SayHi(); workflowEngine.Run(sayHi); //workflowEngine.Run(activity); Console.ReadLine(); }
delegate string SayHi(String name);//定义委托 static void Main(string[] args) { SayHi sayhi = new SayHi(SayHiName); //实例化委托 sayhi("科比"); //一般的直接调用 sayhi.Invoke("张林"); //使用Invoke方法同步调用 //异步调用 sayhi.BeginInvoke("杜兰特", (IAsyncResult ar) => { sayhi.EndInvoke(ar); Console.WriteLine("打招呼成功结束"); }, null); Console.ReadLine(); }
private void Test2_Click(object sender, RoutedEventArgs e) { RandSelect randSelect = delegate() { // 定義一個SayHi變數s1, 利用匿名方法初始化之 SayHi s1 = delegate() { return("Hello world!"); }; SayHi s2 = delegate() { return("It's me, Ryan!"); }; Random c = new Random((int)DateTime.Now.Ticks); double x = c.NextDouble(); string str = x > 0.5 ? s1() : s2(); return(string.Format("{0} \r\n {1}", x, str)); }; test2.Text = randSelect(); }
static void Main(string[] args) { IntroduceYourself("John"); SayHi hey = new SayHi(IntroduceYourself); hey("Cathy"); // Pass it down as an arg and use it in another function Greeting(hey); // Look, ma ... no Instantiation Greeting(IntroduceYourself); EvensAndOddsDemo(); }
static void Greeting(SayHi yo) { yo("Zach"); }
public static void Hello(string name, SayHi delegateSayHi) { delegateSayHi(name); }
static void Test(string name, SayHi del) { del(name); }
void HandleOnGetEventInfoCompleted(SayHi.API.Models.Event obj) { SayHiBootStrapper.SetCurrentEvent (obj); if (obj.IsSucess) { this.InvokeOnMainThread ( delegate { PerformSegue (SayHiConstants.SHVCtoESVCSegue, this); }); } else { this.InvokeOnMainThread ( delegate { SayHiBootStrapper.ShowAlertMessage ("Error", "Could not retrieve event. Be sure that the code is correct and you are connected to a network"); }); } isWaiting = false; }