一道C#难题

[复制链接]
查看11 | 回复2 | 2009-10-7 14:31:55 | 显示全部楼层 |阅读模式
objects不就是个数吗?
回复

使用道具 举报

千问 | 2009-10-7 14:31:55 | 显示全部楼层
源代码如下。使用析构函数就可以调查内存中的学生个数了using System;namespace __2{
class Program
{
static void Main()
{
Student s1 = new Student("王小红");
Student s2 = new Student("周军");
s1 = new Student("Jerry");
}
}
public class Student
{
public static int objects = 0;
public string name;
public Student(string n)
{
name = n;
Console.WriteLine("创建对象个数:{0}"+++objects);
}
~Student()
{
objects --;
Console.WriteLine("创建对象个数:{0}" + objects );
} } }
回复

使用道具 举报

千问 | 2009-10-7 14:31:55 | 显示全部楼层
做不到,换别的方法。昨天给你试了,不行的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行