How to: Cast Objects Returned by Office Applications
When you write managed code, by default you must specify an object's type. However, many methods and properties in the Microsoft Office primary interop assemblies return the type Object, because they have the capability to return several different types. When the object is returned, you must explicitly convert (in Visual Basic) or cast (in C#) the object to the correct type. Converting or casting the object enables IntelliSense for the object in the Code Editor.
The following procedure is an example of casting an object returned by a Microsoft Office application to a specific type for use in managed code. This example uses a document-level customization for Microsoft Office Excel.
To cast an object to a specific type
Add a NamedRange control to cell A1.
Although the underlying value of the ColumnWidth property is a decimal value, the property returns the value as an Object type. You must cast the Object to a Double to work with the decimal value directly.
Display the column width of the NamedRange control in a dialog box.