30 lines
704 B
C#
30 lines
704 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DelegateEventFuncAction
|
|
{
|
|
public class EventTest
|
|
{
|
|
public delegate void CustomEventHandler(string message);
|
|
|
|
public event CustomEventHandler Trigger;
|
|
|
|
public event Action<string> TriggerByAction;
|
|
|
|
public void Notify()
|
|
{
|
|
Random rnd = new Random();
|
|
int r = rnd.Next(0, 10);
|
|
|
|
if (r <= 7 && this.Trigger != null)
|
|
this.Trigger("70% probability");
|
|
|
|
if (r <= 5 && this.TriggerByAction != null)
|
|
this.TriggerByAction("50% probability");
|
|
}
|
|
}
|
|
}
|