i try to generate some codes. i face to face delegates. Everythings is ok.(Look below) But appearing a warning: you shold assing value why? but second code below is ok.
namespace Delegates
{
class Program
{
static void Main(string[] args)
{
HesapMak hesapla = new HesapMak();
hesapla.Calculator = new HesapMak.Hesap(hesapla.Sum);
double sonuc = hesapla.Calculator(34, 2);
Console.WriteLine("Toplama Sonucu:{0}",sonuc.ToString());
Console.ReadKey();
}
}
class HesapMak
{
public double Sum(double s1, double s2)
{
return s1 + s2;
}
public double Cikarma(double s1, double s2)
{
return s1 - s2;
}
public double Multiply(double s1, double s2)
{
return s1 * s2;
}
public double Divide(double s1, double s2)
{
return s1 / s2;
}
public delegate double Hesap(double s1, double s2);
public Hesap Calculator; ----< they want me assingn value
}
}
namespace Delegates
{
class Program
{
static void Main(string[] args)
{
HesapMak hesapla = new HesapMak();
hesapla.Calculator = new HesapMak.Hesap(hesapla.Sum);
double sonuc = hesapla.Calculator(34, 2);
Console.WriteLine("Toplama Sonucu:{0}",sonuc.ToString());
Console.ReadKey();
}
}
class HesapMak
{
public double Sum(double s1, double s2)
{
return s1 + s2;
}
public double Cikarma(double s1, double s2)
{
return s1 - s2;
}
public double Multiply(double s1, double s2)
{
return s1 * s2;
}
public double Divide(double s1, double s2)
{
return s1 / s2;
}
public delegate double Hesap(double s1, double s2);
public Hesap Calculator=null;
}
}