Tuesday, July 1, 2014

I am new to Microsoft.Office.Interop.Excel Marshal.ReleaseComObject

Hi,


To be honest, I did a test and I cloud made my score to 9.5 I don't want o come up with this question but just real curious to know


Which of the following is the correct code to close all references to the com objects below?


Workbooks books = excel.workBooks;

Workbook = book[1];

Sheets sheets = book.WorkSheets;

Worksheet ws = sheet[1];


A: Marshal.ReleaseComObject(book);


B: Marshal.FinalReleaseComObject(books);


C:

Marshal.ReleaseComObject(sheets);

Marshal.ReleaseComObject(books);


D:

Marshal.ReleaseComObject(sheet);

Marshal.ReleaseComObject(sheets);

Marshal.ReleaseComObject(book);

Marshal.ReleaseComObject(books);


We should release all com object isn't? but the question is weird


Worksheet ws = sheet[1];


I chosed D: because of it is the most correct.


No comments:

Post a Comment