Exemplo n.º 1
0
 public Example(ExampleDelegate ed)
 {
     for (int i = 0; i < 10; i++)
     {
         ed(i.ToString());
     }
 }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
    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.
    }
Exemplo n.º 5
0
        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!
        }
Exemplo n.º 6
0
    void Start()
    {
        ExampleDelegate method_to_use = MultDelegate;

        method_to_use.Invoke(5, 5);
        method_to_use = AddDelegate;
        method_to_use.Invoke(5, 5);
    }
Exemplo n.º 7
0
        public Example(ExampleDelegate ed)
        {
            int i = 0;

            while (i < 10)
            {
                ed(i.ToString());
                i++;
            }
        }
Exemplo n.º 8
0
    void Start()
    {
        ExampleDelegate del = Hello;

        del();

        HumanDelegate human = Walk;

        human += Eat;
        human += Sleep;

        human();
    }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            ExampleDelegate exampleDelegate = new ExampleDelegate(SayHello);

            exampleDelegate();
        }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 16
0
 void AddDelegate(int a, int b)
 {
     Debug.Log("Here is the sum: " + (a + b));
     methodToUse = SubtractDelegate;
 }
Exemplo n.º 17
0
 void Start()
 {
     methodToUse = SubtractDelegate;
 }
Exemplo n.º 18
0
 void SubtractDelegate(int a, int b)
 {
     Debug.Log("Here is the difference: " + (a - b));
     methodToUse = AddDelegate;
 }
Exemplo n.º 19
0
 public void SubDelegate(ExampleDelegate exam, string i)
 {
     exam(i);
 }
Exemplo n.º 20
0
    private IEnumerator WaitThenCallBack(float delay, ExampleDelegate exDel)
    {
        yield return(new WaitForSeconds(delay));

        exDel();
    }
Exemplo n.º 21
0
        public void SimpleDelegateExample()
        {
            ExampleDelegate simpleDelegateExample = (message) => message + " example.";

            Clients.Caller.simpleDelegateExample(simpleDelegateExample("Simple delegate"));
        }
 public void Start()
 {
     exampleDelegate = MyFunction; //subscribes function to the delegate
 }