Better way to cast object to int

You have several options: (int) — Cast operator. Works if the object already is an integer at some level in the inheritance hierarchy or if there is an implicit conversion defined. int.Parse()/int.TryParse() — For converting from a string of unknown format. int.ParseExact()/int.TryParseExact() — For converting from a string in a specific format Convert.ToInt32() — For … Read more

How do I properly clean up Excel interop objects?

Excel does not quit because your application is still holding references to COM objects. I guess you’re invoking at least one member of a COM object without assigning it to a variable. For me it was the excelApp.Worksheets object which I directly used without assigning it to a variable: Worksheet sheet = excelApp.Worksheets.Open(…); … Marshal.ReleaseComObject(sheet); … Read more