2011-01-09 20 views
1

我有以下的C#代碼:我需要在4.0'動態'變量上使用Marshal.ReleasComObject嗎?

int CallFooMethod() 
{ 
    Type type = TypeDelegator.GetTypeFromProgID("SomeCOMDll.SomeCOMClass"); 

    dynamic foo = Activator.CreateInstance(type); 

    return (int)foo.Foo(); 
} 

我的問題是,我是否需要使用Marshal.ReleaseComObject的上名爲foo的變量?

我通常會這樣做,如果我以通常的方式使用反射調用COM對象上的方法,但由於動態是關於後期綁定和魔術,我不知道動態類型的變量是否會照顧這對我來說...

感謝

回答

0

You shouldn't call it at all in most situtations,除非你真的知道自己在做什麼。

dynamic不會有什麼區別。 dynamic只是一種調用對象方法的不同方式;它根本不影響對象。

+0

我讀過上面的鏈接,認爲它不適用於我的情況。 – Wes 2011-01-09 21:14:23

相關問題