why assign null value or another default value firstly?

Posted by Phsika on Stack Overflow See other posts from Stack Overflow or by Phsika
Published on 2010-05-31T15:10:10Z Indexed on 2010/05/31 15:12 UTC
Read the original article Hit count: 419

Filed under:
|
|
|

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; } }

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET