delegate_event_virtual1
 
Code :

using System;
using System.Collections.Generic;
//All lambda expressions use the lambda operator =>
//csc delegate_event_virtual1.cs
namespace ConsoleApplication1
{
public class Process
{
public delegate void TriggerChange();
public event TriggerChange transcation;
private int n1;
protected virtual void OnChanged()
{
if (transcation != null)
{ transcation(); Console.WriteLine(";;;;"); }
else {
Console.WriteLine("Event fired. Transaction Completed!");
}
}
// constructor
public Process(int n1) { SetMethod(this.n1=n1); }
public void SetMethod(int n2)
{
if (this.n1!= n2)
{
Console.WriteLine("Invoke OnChange : " + this.n1 + " : " + n2);
OnChanged();
}
else
{
Console.WriteLine("Values were silimar : " + this.n1 + " : " + n2);
}
}
}
class MainClass
{
public static void Main(string[] args)
{
Process PS = new Process(1);
PS.SetMethod(2);
PS.SetMethod(1);
PS.SetMethod(3);

Console.ReadLine();

}

}

}