Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Object Test Bench
 How to: Create and Display an Insta...
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Studio 
How to: Create and Display an Instance of an Object 

You can create object instances and invoke static methods from Class View, Class Designer, the Command window, and the Immediate window, and then display the instance in the Object Test Bench Tool Window.

NoteNote

Class Designer is available in Visual Studio Professional and Enterprise versions only.

NoteNote

The Create Instance and Invoke Static Method commands are not available for code types other than classes and structs. These menus are also not available for generic or abstract classes and structs.

NoteNote

The statements in main() are executed when Create Instance is called. For example, if you created an instance programmatically in main(), you cannot use Create Instance to create an object with the same name. No error message is issued in this case though.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create an instance of a project type object and display it in the Object Test Bench tool window

  1. In the Class View, right-click the name of the class or struct whose instance you want to create.

  2. Click Create Instance to display the public constructors of the class.

  3. Select the constructor to display the Create Instance Dialog Box.

  4. In the Create Instance dialog box, provide the parameters, and then type the name of the object. The name is not provided by default; you must provide a name.

  5. Check the Object Test Bench tool window for the object shape.

To create an instance of a .NET Framework or Class Library referenced type object not appearing in Class Designer

  1. In Class View, right-click the object type in the Project References node. See How to: Work with Class View for more information.

  2. Select the constructor to display the Create Instance dialog box.

  3. In the Create Instance dialog box, provide the parameters, and then select a name of the object.

  4. Check the Object Test Bench tool window for the object shape.

To create an instance of an object and display it in the Object Test Bench tool window from the Command window

  1. If the Command window is not displayed, on the View menu, click Other Windows, and then click Command Window.

  2. In the Command window, type the command to instantiate the object.

    NoteNote

    You can also call methods that do not have void return types from the Command window, and then instantiate their return values in the Object Test Bench.

  3. Check the Object Test Bench tool window for the object shape.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
If you're having trouble, check your solution's startup project      Shadow Chaser   |   Edit   |   Show History
This feature is somewhat broken in Visual Studio 2005. If the "Create Instance" or "Invoke Static Method" menu items are not appearing, try switching your startup project to a Class Library or Windows Application. The object test bench inexplicably refuses to work if the startup type is set to a website project.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker