一般规则何时实现IDisposable [英] General Rule for When to Implement IDisposable

查看:80
本文介绍了一般规则何时实现IDisposable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:这个问题与处置时管理资源和本机资源之间有什么区别? (.NET)等等。

This question is a duplicate of What is the difference between managed and native resources when disposing? (.NET) and many others. Please answer the others if you have something to add.

根据框架设计指南由Krzysztof Cwalina和Brad Abrams提供的包含一次性类型实例的类型应该实现IDisposable。

According to the Framework Design Guidelines by Krzysztof Cwalina and Brad Abrams, a type that contains instances of disposable types should implement IDisposable.

有没有其他一般的经验法则是在最佳实践中实现IDisposable?

Is there any other general rule of thumb for when it is best practice to implement IDisposable?

推荐答案

当您有一个类包装非托管资源或当您的类具有实现IDisposable的字段时,实施IDisposable。

Implement IDisposable when you have a class what wraps an unmanaged resource or when your class has a field that implements IDisposable.

这篇关于一般规则何时实现IDisposable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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