问题
doing some office Interop and the code is of Type
try
{
selection = getSelected(Return.Some.Office.InteropObject);
for ( int i = 0 ; i < selection.count ; i++)
yield return selection.item(i)
}
finally
{
Marshal.ReleaseComObject(selection);
}
Wondering if it's a good idea to replace it with a DisposableAction and change to
using ( var a = new DisposableAction(getSelected(Return.Some.Office.InteropObject)) )
{
foreach(var b in a.Items)
yield return b;
}
来源:https://stackoverflow.com/questions/9696115/disposableaction-and-marshal-releasecomobject