static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            List <Student> stuList = new List <Student>();

            stuList.Add(new Student("Adam", 33, 23));
            stuList.Add(new Student("Bob", 30, 23));
            stuList.Add(new Student("Charlie", 29, 23));
            stuList.Add(new Student("Dan", 60, 23));

            //initializing a delegate
            classifierDel classify = new classifierDel(myRules);

            //passing delegate
            Student.computeClassification(stuList, classify);


            //method has delegate signature may have client's own logic.
            void myRules(Student s)
            {
                if (s.Credits == 30)
                {
                    Console.WriteLine(s.Name + " will be a freshman");
                }
                else if (s.Credits == 60)
                {
                    Console.WriteLine(s.Name + " You will be a sophomore");
                }
                else
                {
                    Console.WriteLine(s.Name + " Invalid Data");
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            List <Student> stuList = new List <Student>();

            stuList.Add(new Student("Adam", 33, 23));
            stuList.Add(new Student("Bob", 30, 23));
            stuList.Add(new Student("Charlie", 29, 23));
            stuList.Add(new Student("Dan", 60, 23));

            Student.computeClassification(stuList, classify);
            ugClassifireDel classify = new ugClassifireDel(UMKC);

            void UMKC(Student s)
            {
                if (s.Credits == 30)
                {
                    Console.WriteLine(s.Name + " will be a freshman");
                }
                else if (s.Credits == 60)
                {
                    Console.WriteLine(s.Name + " You will be a sophomore");
                }
                else
                {
                    Console.WriteLine(s.Name + " Invalid Data");
                }
            }
        }