您的位置:首页 > 其它

27析构函数,垃圾回收及类的实例演练

2013-05-03 22:39 176 查看
析构函数自动删除对象

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiGou
{
class Program
{
static void Main(string[] args)
{
Cat kitty = new Cat("kitty",5);
Console.WriteLine("倒数第一句");
}
}

class Cat
{
public string name;
public int age;
public Cat(string nameValue,int ageValue)
{
name=nameValue;
age=ageValue;
Console.WriteLine("一只猫生了,调用构造函数");
}
~Cat()
//析构函数
{

Console.WriteLine("一只猫死了,调用析构函数");
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: