static void Main(string[] args) { GreetDelegate helloDelegate = new GreetDelegate(SayHello); GreetDelegate byeDelegate = new GreetDelegate(SayGoodbye); GreetDelegate hiDelegate = new GreetDelegate(x => Console.WriteLine($"Hi {x}")); helloDelegate("SEDC"); byeDelegate("Freddy"); hiDelegate("Ana"); SayWhatever("Paul", SayHello); SayWhatever("Bill", SayGoodbye); SayWhatever("Ana", x => { Console.WriteLine($"Hello from SEDC {x}"); Console.WriteLine($"Goodbye from SEDC {x}"); }); NumbersOperation(2, 3, (x, y) => x + y); NumbersOperation(2, 3, (x, y) => x - y); NumbersOperation(2, 3, (x, y) => { if (x > y) { return(x); } return(y); }); Console.ReadLine(); }
static void runAsynchronousCall(NetRemotingObjects.Hello obj, string name, List<string> names) { // calling synchronous methods asynchronously. // [ref] http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx GreetDelegate greetDelegate = new GreetDelegate(obj.greet); IAsyncResult greetAsyncResult = greetDelegate.BeginInvoke(name, null, null); GreetAllDelegate greetAllDelegate = new GreetAllDelegate(obj.greetAll); IAsyncResult greetAllAsyncResult = greetAllDelegate.BeginInvoke(names, null, null); // do something and then wait greetAsyncResult.AsyncWaitHandle.WaitOne(); greetAllAsyncResult.AsyncWaitHandle.WaitOne(); string greeting = null; if (greetAsyncResult.IsCompleted) greeting = greetDelegate.EndInvoke(greetAsyncResult); List<NetRemotingObjects.HelloMessage> greetingMsgs = null; if (greetAllAsyncResult.IsCompleted) greetingMsgs = greetAllDelegate.EndInvoke(greetAllAsyncResult); if (null != greeting) Console.WriteLine(greeting); else Console.WriteLine("NetRemotingObjects.Hello.greet() call error"); if (null != greetingMsgs) foreach (NetRemotingObjects.HelloMessage msg in greetingMsgs) Console.WriteLine(msg.Message); else Console.WriteLine("NetRemotingObjects.Hello.greetAll() call error"); }
public Form1() { //InitializeComponent(); GreetDelegate delegate1 = new GreetDelegate(EnglishGreet); GreetPeople("xX", EnglishGreet); GreetPeople("xx", delegate1); }
private void PersonCame(Person p, DateTime d) { Console.WriteLine("{0} comes on work.", p.Name); if (greetAll != null) { greetAll(p.Name, "", d); } greetAll += p.Greet; sayBy += p.TellGoodbye; }
static void Main(string[] args) { string s1 = "KDW", s2 = "万锴迪"; GreetDelegate delegate1 = new GreetDelegate(EnglishGreeting); delegate1 += ChineseGreeting; GreetPeople(s1, EnglishGreeting); GreetPeople(s2, ChineseGreeting); Console.WriteLine(); GreetPeople(s1, delegate1); Console.ReadKey(); }
private void PersonLeave(Person p) { Console.WriteLine("{0} leaves workplace.", p.Name); greetAll -= p.Greet; sayBy -= p.TellGoodbye; RemoveListeners(p); if (sayBy != null) { sayBy(p.Name, ""); } }
static void runAsynchronousCall(NetRemotingObjects.Hello obj, string name, List <string> names) { // calling synchronous methods asynchronously. // [ref] http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx GreetDelegate greetDelegate = new GreetDelegate(obj.greet); IAsyncResult greetAsyncResult = greetDelegate.BeginInvoke(name, null, null); GreetAllDelegate greetAllDelegate = new GreetAllDelegate(obj.greetAll); IAsyncResult greetAllAsyncResult = greetAllDelegate.BeginInvoke(names, null, null); // do something and then wait greetAsyncResult.AsyncWaitHandle.WaitOne(); greetAllAsyncResult.AsyncWaitHandle.WaitOne(); string greeting = null; if (greetAsyncResult.IsCompleted) { greeting = greetDelegate.EndInvoke(greetAsyncResult); } List <NetRemotingObjects.HelloMessage> greetingMsgs = null; if (greetAllAsyncResult.IsCompleted) { greetingMsgs = greetAllDelegate.EndInvoke(greetAllAsyncResult); } if (null != greeting) { Console.WriteLine(greeting); } else { Console.WriteLine("NetRemotingObjects.Hello.greet() call error"); } if (null != greetingMsgs) { foreach (NetRemotingObjects.HelloMessage msg in greetingMsgs) { Console.WriteLine(msg.Message); } } else { Console.WriteLine("NetRemotingObjects.Hello.greetAll() call error"); } }
static void Main(string[] args) { List <Employee> lstEmployees = new List <Employee>() { new Employee { EmpId = 102, EmpName = "Sue", Salary = 5000, Experience = 5 }, new Employee { EmpId = 202, EmpName = "John", Salary = 600, Experience = 4 }, new Employee { EmpId = 302, EmpName = "Jack", Salary = 3000, Experience = 3 }, new Employee { EmpId = 402, EmpName = "Peter", Salary = 700, Experience = 6 }, new Employee { EmpId = 502, EmpName = "Kelly", Salary = 700, Experience = 5 }, new Employee { EmpId = 503, EmpName = "Peter", Salary = 650, Experience = 5 } }; IsPromotable isPromotable = new IsPromotable(IsEligibleForPromotion); Employee.PromoteEmployee(lstEmployees, isPromotable); Console.WriteLine("Promotion using lambda expression"); Employee.PromoteEmployee(lstEmployees, emp => emp.Experience >= 5); //Console.WriteLine("FindMethod1 result:" + FindMethod1(lstEmployees)); FindMethod1(lstEmployees); FindMethod2(lstEmployees); FindMethod3(lstEmployees); Greet("Subhas"); GreetDelegate greetdel = new GreetDelegate(Greet); greetdel("Spider Man"); Console.ReadLine(); }
public static void Load() { // Initialize DLL _libraryHandle = LoadLibrary(Application.dataPath + _LIB_PATH); Debug.Log("Library Path:" + Application.dataPath + _LIB_PATH); Debug.Log("Library Handle:" + _libraryHandle); // Request unity interface ptr ulong unityInterface = GetUnityInterfacePtr(); Debug.Log("Unity Interface: " + unityInterface); // Init & Unload _initDelegate = GetDelegate <InitDelegate>(_libraryHandle, "Init"); _initDelegate(unityInterface); _unloadDelegate = GetDelegate <UnloadDelegate>(_libraryHandle, "Unload"); // Logging _registerDebugCallback = GetDelegate <LogDelegate>(_libraryHandle, "RegisterDebugCallback"); _registerDebugCallback(OnDebugCallback); // Greet _delegateGreet = GetDelegate <GreetDelegate>(_libraryHandle, "Greet"); // IsReady _isReadyDelegate = GetDelegate <IsReadyDelegate>(_libraryHandle, "IsReady"); // CreateSender _createSenderDelegate = GetDelegate <CreateSenderDelegate>(_libraryHandle, "CreateSender"); // CreateReceiver _createReceiverDelegate = GetDelegate <CreateReceiverDelegate>(_libraryHandle, "CreateReceiver"); // GetTexturePointer _getTexturePointerDelegate = GetDelegate <GetTexturePointerDelegate>(_libraryHandle, "GetTexturePointer"); // GetTextureWidth _getTextureWidthDelegate = GetDelegate <GetTextureWidthDelegate>(_libraryHandle, "GetTextureWidth"); // GetTextureHeight _getTextureHeightDelegate = GetDelegate <GetTextureHeightDelegate>(_libraryHandle, "GetTextureHeight"); // GetTextureFormat _getTextureFormatDelegate = GetDelegate <GetTextureFormatDelegate>(_libraryHandle, "GetTextureFormat"); // GetSharedHandle _getSharedHandleDelegate = GetDelegate <GetSharedHandleDelegate>(_libraryHandle, "GetSharedHandle"); }
public void GreetPeople(string name, GreetDelegate MakeGreet) { MakeGreet(name); }
private static void GreetPeople(string name, GreetDelegate MakeGreeting) { MakeGreeting(name); }
public static void Greeting(string name, GreetDelegate gd) { gd(name); }
public static void SayWhatever(string message, GreetDelegate greetDelegate) { Console.WriteLine("Inside SayWhatever:"); greetDelegate(message); }