Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C# OOP Events Lambda

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Events_Lambda
{
    // Object Orianted Programmeng
    // Lambda

    // delegate
    public delegate void myDelegate();

    // class
    class Absence // الغياب
    {
        // Event
        public event myDelegate AbsenceEvent;

        public int Absented_Hours;


        // Propertys
        public int Absented_Hours_Property
        {
            get { return Absented_Hours; }
            set { Absented_Hours = value; }
        }

        public Absence(int Hours)
        {
            this.Absented_Hours = Hours;
        }

        public void Verify_Absence(int Max_hours)
        {
            if (Absented_Hours > Max_hours)
            {
                AbsenceEvent();
            }
        }

        /* test one
        public void AlertEvent()
        {
            Console.WriteLine("Warning !");
        }*/


    }
    class Program
    {
        static void Main(string[] args)
        {

            // Lambda
            // example one
            Absence myAbsence = new Absence(10);

            myAbsence.AbsenceEvent += () => Console.WriteLine("Warning !");

            myAbsence.Verify_Absence(8);


            // Lambda
            // example tow
            List<string> Colors = new List<string> { "Red", "Blue", "Orange", "black" };

            Colors.ForEach(Item =>
                {
                    Console.Write("\n\tColors are: - " + Item);
                });

        }
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.