程序如下usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classPeople{publicintnum;publicstaticintTotalPeople=0;p...
程序如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class People
{
public int num;
public static int TotalPeople=0;
public static void ShowTotalPeople()
{
Console.WriteLine("现在共有{0}个人进入会场",TotalPeople);
}
public void ShowQuery(string name)
{
Console.WriteLine("{0}是第{1}个人进入会场的人",name,num);
}
public People()
{
TotalPeople++;
num=TotalPeople;
}
~People()
{
TotalPeople--;
}
}
class myclass
{
static void Main(string[] args)
{
People.ShowTotalPeople();
People MrGreen=new People();
Console.WriteLine("MrGreen是第{0}个进入会场的人",MrGreen.num);
People.ShowTotalPeople();
People MrSmith=new People();
People MrAllen=new People();
MrSmith.ShowQuery("MrSmith");
MrAllen.ShowQuery("MrAllen");
People.ShowTotalPeople();
People pPeople;
pPeople.ShowTotalPeople();
pPeople=MrSmith;
pPeople.ShowQuery("pPeople");
Console.ReadLine();
}
}
}
初学 不懂额 求解答