コード例 #1
0
        public void FirstDelegateMethod(FirstDelegate method)
        {
            FirstDelegate firstDelegate = new FirstDelegate(method);

            firstDelegate.Invoke();
            //or
            firstDelegate();
        }
コード例 #2
0
        public static void Main()
        {
// Using the old .Net 1/1.1 syntax

            FirstDelegate d1 = new FirstDelegate(Program.StaticMethod);

            Program instance = new Program("Created my instance");

            instance.name = "My instance";
            FirstDelegate d2 = new FirstDelegate(instance.InstanceMethod);


            Console.WriteLine(d1(10)); // Writes out "Static method: 10"
            Console.WriteLine(d2(5));  // Writes out "My instance: 5"

//  Using new simplified syntax

            FirstDelegate n1 = StaticMethod;
            FirstDelegate n2 = (new Program("Instance new way")).InstanceMethod;

            Console.WriteLine(n1.Invoke(88));
            Console.WriteLine(n2.Invoke(22));

            Console.WriteLine(n1(101));  // Writes out "Static method: 10"
            Console.WriteLine(n2(102));  // Writes out "My instance: 5"


            Dictionary <string, string> dc1 = new Dictionary <string, string>();

            dc1.Add("Yuriy", "Gruzglin");
            dc1.Add("Anna", "Montana");
            dc1.Add("Joy", "Bennet");
            dc1["Stella"] = "Artoit";

            dc1.Append(new KeyValuePair <string, string>("Gerald", "Ford"));
            dc1.Append(new KeyValuePair <string, string>("Ray", "Holmes"));

            foreach (KeyValuePair <string, string> z in dc1)
            {
                Console.WriteLine(z.Key + "   " + z.Value);
            }

            string y;

            if (dc1.TryGetValue("Joy", out y))
            {
                Console.WriteLine("Joy  " + y);
            }

            Console.ReadLine();
        }
コード例 #3
0
        public bool Tick(IDescription description)
        {
            if (time == -1)
            {
                if (trigger(description))
                {
                    onFinal?.Invoke(description);
                    return(true);
                }

                onTick?.Invoke(description);
            }
            else if (IsStarted() || (trigger?.Invoke(description) ?? true))
            {
                if (time == Duration)
                {
                    onFirst?.Invoke(description);
                }
                if (time > 1)
                {
                    onTick?.Invoke(description);
                }
                else if (time > 0)
                {
                    onFinal?.Invoke(description);
                    return(true);
                }

                if (time > 0)
                {
                    time--;
                }
            }

            return(false);
        }