下面这个程序中m,n不是没有被付值吗,怎么会有值?
using System;
namespace ConsoleApplication1{ /// <summary>
/// Class1 的摘要说明。
/// </summary>
///
///

///<summary>
/// 应用程序的主入口点。
/// </summary>
//[STAThread]
class a
{
protected internal int m;
public static int n;
public void display()
{  
m++;
n++;
Console.WriteLine(m);
Console.WriteLine(n);
}
}
class Class1
{
static void Main(string[] args)

  {
  a a1=new a();
a1.display();
a a2=new a();
a2.display();
a a3= new a();
a3.display();
     
  string s=Console.ReadLine();
Console.WriteLine(s);
  Console.ReadLine();

  //
  // TODO: 在此处添加代码以启动应用程序
  //
  }

}
}

解决方案 »

  1.   

    a2.display();
    a3.display();
    静态变量
      

  2.   

    public void display()
    {  
    m++;//是不是已经递加了。。
    n++;
    Console.WriteLine(m);
    Console.WriteLine(n);
    }
      

  3.   

    值对象会被.net框架初始化
      

  4.   

    m,n初始化后值都是1吗,那如果是 double 类型的呢
      

  5.   

    m,n的初始值都是0
    public void display()
    {  
    m++;
    n++;
    Console.WriteLine(m);
    Console.WriteLine(n);
    }
    你首先调用m++;所以,你的输出应该是从1开始!!!
      

  6.   

    所有的NUM类型都一样啊,他是没有NULL值的!
      

  7.   

    using System;
    namespace ConsoleApplication1{ /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    ///
    ///

    ///<summary>
    /// 应用程序的主入口点。
    /// </summary>
    //[STAThread]
    internal  class a
    {
    protected internal double m;
    public static int n;
    internal void display()
    {  
    m++;
    n++;
    Console.WriteLine(m);
    Console.WriteLine(n);
    }
    }
     internal class b:  a
    {
    public void display1()
           {
                  display();
    Console.WriteLine("nihaoa  ");
    }
     }
    class Class1
    {
    static void Main(string[] args)

      {
      b a1=new b();
    a1.display();
    Console.WriteLine(a1.m);////////为什么可以直接访问m
    a a2=new a();
    a2.display();     
      string s=Console.ReadLine();
    Console.WriteLine(s);
      Console.ReadLine();

      //
      // TODO: 在此处添加代码以启动应用程序
      //
      }

    }
    }我在class a中已经把m设定为internal 了,那为什么在main中还可以直接访问,internal不是显示指定该类只有项目内部才嫩访问吗?
      

  8.   

    1.static int 默认初始化为0;
    2.internal可以被本组合体(Assembly)内所有的类存取,组合体是C#语言中类被组合后的逻辑单位和物理单位,其编译后的文件扩展名往往是“.DLL”或“.EXE”。class a和class1是在一个组合体中.
      

  9.   

    楼主可能还不明白
    internal
    private
    protect
    public 所表示的意思
    想知道更多,买本书吧!或者给多点分!
    哈,我还要做星呢!