我有兩個類,分別是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
是的...這是打算... –