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();
}
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
SatSargsyan/Delegates
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 0
No packages published