Assume you have a base class and another class derived from it. You have events defined in base class so you wish to use them in the derived class.
class a
{
public delegate void Amanindelegate();
public event Amanindelegate Amanin;
}
class b:a
{
public void hey0()
{
Amanin();
}
}
class Program
{
static void Main(string[] args)
{
b b1=new b();
b1.Amanin+=new a.Amanindelegate(b1_Amanin);
b1.hey0();
}
static void b1_Amanin()
{
Console.WriteLine("aboovv");
}
}
Here you have the mentioned error in hey0 method line Amanin();
The best practice is as follows.
class a
{
public delegate void Amanindelegate();
public virtual event Amanindelegate Amanin;
}
class b:a
{
public override event a.Amanindelegate Amanin;
public void hey0()
{
Amanin();
}
}
class Program
{
static void Main(string[] args)
{
b b1=new b();
b1.Amanin+=new a.Amanindelegate(b1_Amanin);
b1.hey0();
}
static void b1_Amanin()
{
Console.WriteLine("aboovv");
}
}