C# 构造函数 后面跟了一个 ~ 又跟了一个同名方法。是什么意思?

[复制链接]
查看11 | 回复3 | 2011-3-7 11:35:17 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace WindowsFormsApplication1
{

public class AddressBookController

{

public AddressBookController()

{

this.dataContext=new AddressBookClassesDataContext();

this.BookBindingList = this.dataContext.Table1TabAddressBook.GetNewBindingList();

}

~AddressBookController()

{

if(this.dataContext !=null)

{

this.dataContext.Dispose();

}

}

public AddressBookClassesDataContext dataContext;

public IBindingList BookBindingList { get; private set; }

}

////
}

回复

使用道具 举报

千问 | 2011-3-7 11:35:17 | 显示全部楼层
~AddressBookController()
{
if(this.dataContext !=null)
{
this.dataContext.Dispose();
}
}这个是析构函数。就是构造函数前加上~符号。使用析构函数主要是释放资源。当你关闭程序的时候,就是调用析构函数。更多、全面的了解请搜索 析构函数。
回复

使用道具 举报

千问 | 2011-3-7 11:35:17 | 显示全部楼层
这个是析构函数,,在你使用完该函数以后通过调用该函数释放刚才所使用的空间
回复

使用道具 举报

千问 | 2011-3-7 11:35:17 | 显示全部楼层
对,这是析构函数,可以不写,系统自动为你准备一个空的函数,一般用不到
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行