Skip to content

This program is example how to use Delegates(.net framework 4.6, C# 6.0).

Notifications You must be signed in to change notification settings

SatSargsyan/Delegates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delegates

using System;

namespace Delegates
{

    public delegate void Del(object о); 

    class Subj
    {
        Del dels;
        
        public void Register(Del d) 
        {
            dels += d;
        }
        public void OOPS()
        {
            //Console.WriteLine("O----OOPS!");
            if (dels!= null) dels(this);
        }

    }


    class ObsA  
    {
        public void Do(object о) 
        {
            Console.WriteLine("I see, that OOPS!");
        }
    }
    
    class ObsB 
    {
        public static void See(object о) 
        {
            Console.WriteLine("I see too, that OOPS!");
        }
    }
    class Program
    {
        static void Main()
        {
            Subj s = new Subj();              

            ObsA o1 = new ObsA();
            ObsA o2 = new ObsA(); 

            s.Register(new Del(o1.Do));
            s.Register(new Del(o2.Do));
            s.Register(new Del(ObsB.See));//( is calling by name class, because the method is static )

            s.OOPS(); 
            Console.ReadKey();
        }
    }
}

About delegates

ev3

About

This program is example how to use Delegates(.net framework 4.6, C# 6.0).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages