我有两个类,分别是MyFirstClass
和MyAnotherClass
,MyAnotherClass
是实现IDiposable接口。这是否处理子对象?
public class MyFirstClass
{
public string xyz{get;set;} ..... and so on
}
public class MyAnotherClass : IDisposable
{
private readonly MyFirstClass objFc = new MyFirstClass();
public static void MyStaticMethod()
{
var objOfFirstClass = new MyFirstClass();
// something with above object
}
public void MyNonStaticMethod()
{
// do something with objFc
}
#region Implementation of IDisposable
.... my implementations
#endregion
}
现在我又多了一个课堂,我打电话MyAnotherClass
,像这样
using(var anotherObj = new MyAnotherClass())
{
// call both static and non static methods here, just for sake of example.
// some pretty cool stuffs goes here... :)
}
所以我想知道,我应该担心我的对象的清理方案?另外,我的ObjFC
(非静态内部)和objOfFirstClass
(静态内部)会发生什么情况。
据我所知,使用是会照顾的......但我需要知道更多...
“MyFirstClass”类不实现“IDisposable”。这是故意的吗? – Yogu
是的...这是打算... –