repl.it
@kironroy/

events

C#

No description

fork
loading
Files
  • main.cs
  • ClownSchoolModel.cs
  • ConsoleHelpers.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;

namespace CoreyEventsHW
{
    class Program
    {
        static void Main(string[] args)
        {
            ClownSchoolModel pieThrowing = new ClownSchoolModel("\"Art of Pie Throwing\"", 3);
            ClownSchoolModel whoopeeCushion = new ClownSchoolModel("\"Whoopee Cushion 101\"", 3);

            // Event listener  wired up
            pieThrowing.EnrollmentFullClown += CollegeClass_EnrollmentFull;

            "".PrintToConsole();
            pieThrowing.SignUpClown("Mita").PrintToConsole();
            pieThrowing.SignUpClown("Lita").PrintToConsole();
            pieThrowing.SignUpClown("Rita").PrintToConsole();
            pieThrowing.SignUpClown("Sita").PrintToConsole();
            pieThrowing.SignUpClown("Gita").PrintToConsole();

            // Event listener  wired up
            whoopeeCushion.EnrollmentFullClown += CollegeClass_EnrollmentFull;

            whoopeeCushion.SignUpClown("Lita").PrintToConsole();
            whoopeeCushion.SignUpClown("Mita").PrintToConsole();
            whoopeeCushion.SignUpClown("Rita").PrintToConsole();
            whoopeeCushion.SignUpClown("Sita").PrintToConsole();
            whoopeeCushion.SignUpClown("Gita").PrintToConsole();

            Console.ReadLine();
        }

        // 1 type of event in 2 different class instances 
        // that are being handled by the same method 

        // Event listener 
        private static void CollegeClass_EnrollmentFull(object sender, string e)
        {
            ClownSchoolModel model = (ClownSchoolModel)sender; // right type sent to college model

            Console.WriteLine();
            Console.WriteLine($"{model.ClownClasstitle}: Full");
            Console.WriteLine();

        }
    }
}