public Example(ExampleDelegate ed) { for (int i = 0; i < 10; i++) { ed(i.ToString()); } }
static void Main(string[] args) { CreateWolf wolf = delegate(string name) { var newWolf = new BigBadWolf(name); return(newWolf); }; wolf("Grey Wolf").GetInfo(); Console.WriteLine(); BigBadWolf myWolf = new BigBadWolf("Grey"); WoofWolf woof = myWolf.Woof; ExampleDelegate exampleHello = Greeting.Hello; ExampleDelegate exampleBye = Greeting.Bye; ExampleDelegate exampleGoodMorning = Greeting.GoodMorning; ExampleDelegate GoodEvening = Greeting.GoodEvening; ExampleDelegate combinedExample = exampleHello + exampleBye + exampleGoodMorning + GoodEvening; combinedExample(); ExampleDelegate combinedHelloBye = combinedExample - exampleGoodMorning - GoodEvening; combinedHelloBye(); ExampleDelegate combinedMorningEvening = combinedExample - exampleHello - exampleBye; combinedMorningEvening(); }
static void Main(string[] args) { //Example e = new Example(); //int a = 5; //int b = 25; ////Console.Write("Result: {0}", e.addition(a, b)); //calculation calculationDelegate = new calculation(e.addition); ////Console.Write("Result: {0} + {1} = {2}", a, b, calculationDelegate.Invoke(a, b)); //Console.WriteLine("Result: {0}", calculationDelegate(a, b)); //string s = "Khanh"; //message Mes = new message(e.hello) + new message(e.goodbye); //Mes(s); ExampleDelegate ed = DelegateAsParams; Example e0 = new Example(ed); Console.ReadLine(); Example e1 = new Example(delegate(string s) { Console.WriteLine(s); }); Console.ReadLine(); }
public IEnumerator PlayAnim(ExampleDelegate function, short move, float speed) { yield return(new WaitForSeconds(speed)); // > mai mare =>>> slow , < mai mic =>>> fast function(move); StopCoroutine("PlayAnim"); // Important , keep it to stop call this function. }
void Main(string[] args) { // Originial delegate initialization syntax with a named method. ExampleDelegate a = AddOne; Func <int, int> b = AddOne; // Delegate initialization with an inline anonymous method. // This syntax was introduced with C# version 2.0. ExampleDelegate bx = delegate(int i) { return(i + 1); }; // C# version 3.0 introduces a ExampleDelegate c = i => i + 1; // The code provided will print ‘Hello World’ to the console. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. Console.WriteLine("Hello World!"); Console.ReadKey(); Func <int, int> addOne = x => x + 1; int result = addOne(2); List <string> redVehicles = new List <string>(); var bla = new Animal(); // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! }
void Start() { ExampleDelegate method_to_use = MultDelegate; method_to_use.Invoke(5, 5); method_to_use = AddDelegate; method_to_use.Invoke(5, 5); }
public Example(ExampleDelegate ed) { int i = 0; while (i < 10) { ed(i.ToString()); i++; } }
void Start() { ExampleDelegate del = Hello; del(); HumanDelegate human = Walk; human += Eat; human += Sleep; human(); }
public void AsyncDelegateExample() { ExampleDelegate asyncDelegate = (message) => { for (var count = 0; count < 5; count++) { Clients.Caller.asyncDelegateExample("This is message " + count + "."); } return("The async method has finished." + message); }; asyncDelegate.BeginInvoke(" Hello There.", AsyncCallBackExample, null); }
public static void Main() { ExampleDelegate ex1Delegate, ex2Delegate, ex3Delegate, myDelegate; ex1Delegate = new ExampleDelegate(Method1); ex2Delegate = new ExampleDelegate(Method2); ex3Delegate = ex1Delegate + ex2Delegate; ex1Delegate("AAA"); ex2Delegate("BBB"); ex3Delegate("CCC"); myDelegate("DDD"); myDelegate = ex3Delegate - ex1Delegate; myDelegate("EEE"); myDelegate = ex3Delegate - ex2Delegate; myDelegate("FFF"); Console.ReadLine(); }
static void Main(string[] args) { ExampleDelegate exampleDelegate = new ExampleDelegate(SayHello); exampleDelegate(); }
public void Start(ExampleDelegate d) { Console.WriteLine("Сейчас произойдет что-то связанное с цифрой 5"); d.Invoke(5); }
public ExampleDelegate exampleDelegate; //instance of the delegate private void OnEnable() { exampleDelegate += MyFunction; //add a function exampleDelegate += MyOtherFunction; //add another function }
private void OnDisable() { exampleDelegate -= MyFunction; //remove a functoion exampleDelegate -= MyOtherFunction; //remove another function }
static void Main(string[] args) { ExampleDelegate sample1 = new ExampleDelegate(SampleMethod); ExampleDelegate sample2 = SampleMethod; }
void AddDelegate(int a, int b) { Debug.Log("Here is the sum: " + (a + b)); methodToUse = SubtractDelegate; }
void Start() { methodToUse = SubtractDelegate; }
void SubtractDelegate(int a, int b) { Debug.Log("Here is the difference: " + (a - b)); methodToUse = AddDelegate; }
public void SubDelegate(ExampleDelegate exam, string i) { exam(i); }
private IEnumerator WaitThenCallBack(float delay, ExampleDelegate exDel) { yield return(new WaitForSeconds(delay)); exDel(); }
public void SimpleDelegateExample() { ExampleDelegate simpleDelegateExample = (message) => message + " example."; Clients.Caller.simpleDelegateExample(simpleDelegateExample("Simple delegate")); }
public void Start() { exampleDelegate = MyFunction; //subscribes function to the delegate }