Answer to Question #224155 in C# for nikitha

Question #224155
student scholarship code using delegates in c#
1
Expert's answer
2021-08-07T12:36:08-0400
public class University
    {
        public delegate void GrantScholarshipDelegate();
        public event GrantScholarshipDelegate GrantScholarship;


        public void AddStudent(Student student)
        {
            GrantScholarship += student.GetScholarship;
        }




        private void OnGrantScholarship()
        {
            GrantScholarship?.Invoke();
        }


        public void TimeToSendScholarship()
        {
            OnGrantScholarship();
        }
    }


    public class Student
    {
        public string Name { get; set; }
        public void GetScholarship()
        {
            Console.WriteLine($"Student {Name} has received scholarship!");
        }
    }




    class Program
    {
        static void Main(string[] args)
        {
            University university = new University();
            university.AddStudent(new Student() { Name = "Max" });


            university.TimeToSendScholarship();


            Console.ReadKey();
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS