在C#中使用析构函数? [英] Use of destructor in c#?

查看:802
本文介绍了在C#中使用析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑在C#中使用析构函数。在我的知识,我们不能叫 析构函数acording我希望它会自动调用垃圾收集之前进行一些工作过的类(对象),所以我想,如果我们在C#中使用析构函数,然后磨片,我们需要垃圾收集问。由于我知道,析构函数可以照顾内存中,然后我们为什么需要垃圾收集器?

I am little bit confused about use of destructor in c#. In my knowledge we can't call destructor acording to my wish it will call automatically before garbage collector for performing some work over class (object) so i want to ask if we are using destructor in c# then whe we need to garbage collector. As i know that destructor can take care of memory then why we need to garbage collector ?

推荐答案

大家想着垃圾收集错误的方式

一个正确编写的程序不能   假定终结都不会运行。

A correctly-written program cannot assume that finalizers will ever run.

这篇关于在C#中使用析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆