English 中文(简体)
为什么首先转让无效价值或另一种违约价值?
原标题:why assign null value or another default value firstly?

i 试图制定一些法典。 i 面对代表。 一切都ok。 (见下文) 但似乎有一种警告:你坚持为什么有价值? 但下面的二部法典是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:{0iii",sonuc.ToString());
        Console.ReadKey();
    iii
iii

class HesapMak
{
   public double Sum(double s1, double s2)
    {
        return s1 + s2;
    iii

   public double Cikarma(double s1, double s2)
    {
        return s1 - s2;
    iii

   public double Multiply(double s1, double s2)
    {
        return s1 * s2;
    iii
   public double Divide(double s1, double s2)
    {
        return s1 / s2;
    iii
      public delegate double Hesap(double s1, double s2);
      public Hesap Calculator; ----< they want me assingn value

iii

iii

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:{0iii",sonuc.ToString()); Console.ReadKey(); iii iii class HesapMak { public double Sum(double s1, double s2) { return s1 + s2; iii public double Cikarma(double s1, double s2) { return s1 - s2; iii public double Multiply(double s1, double s2) { return s1 * s2; iii public double Divide(double s1, double s2) { return s1 / s2; iii public delegate double Hesap(double s1, double s2); public Hesap Calculator=null; iii iii
最佳回答

This is not neccessary and should not result in a warning.
Section 10.4.4 of the C# (3.0) spec says:

The initial value of a field, whether it be a static field or an instance field, is the default value (Section 5.2) of the field s type. It is not possible to observe the value of a field before this default initialization has occurred, and a field is thus never "uninitialized". The following categories of variables are automatically initialized to their default values:

C# (3.0) spec第5.2节:

变量的缺省值取决于变量的类型,确定如下:

  • For a variable of a value-type, the default value is the same as the value computed by the value-type s default constructor (Section 4.1.1).
  • For a variable of a reference-type, the default value is null.

每天由总部印发的文件清单 Hesap 计算器; 自动输入到其违约值(null)。

问题回答

页: 1 因此,汇编者可以立即看到外地的每一次使用<代码>计算器/代码>。

如果在你的代码中,你没有指派到<代码>计算或,汇编者将给你警告。 这是因为这个领域是不必要的。

一旦你开始在你的法典中某个地方使用这个领域,就会发出警告。 因此,现在就忽视了它并写了字。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签