Beispiel #1
0
        static void Main(string[] args)
        {
            //Delegate
            var subs = new Subs();

            new User("u1").Upload(subs);
            new User("u2").Upload(subs);
            new User("u3").Upload(subs);
            subs.Uploads  = null;
            subs.Uploads += () => { Console.WriteLine("reset"); };
            new User("u4").Upload(subs);

            subs.Uploads();

            Console.WriteLine();

            //Event
            //only -=, += ; no direct call outside class
            var subsEvent = new SubsEvent();

            subsEvent.Uploads += () => { Console.WriteLine("Ev1"); };
            subsEvent.Uploads += () => { Console.WriteLine("Ev2"); };

            subsEvent.GetUploads();

            var subsEvent2 = new SubsEvent2();

            subsEvent2.Uploads += (object s, EventArgs e) => { Console.WriteLine("Evh1"); };
            subsEvent2.Uploads += (object s, EventArgs e) => { Console.WriteLine("Evh2"); };

            subsEvent2.GetUploads();
        }
Beispiel #2
0
 public void Upload(Subs s)
 {
     s.Uploads += () => { Console.WriteLine($"{Name} uploaded"); };
 }