How to: Automate Objects Using Managed Code
When you write managed code, by default you must specify an object's type. However, many Office object model methods and properties 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.
For information on conversion in Visual Basic, seeand . For information on casting in C#, see .
The following procedure is an example of casting an object returned by Office to a specific type for use in managed code.
To cast an object to a specific type
Add acontrol to cell A1.
Cast the object returned from the column width of the named range to a double and assign it to a variable.
Display the column width of the NamedRange control in a dialog box.