Aracılığıyla paylaş


How to: Add Parameters to a Method (Class Designer)

Add parameters to methods using the Class Details window. Parameters can be configured to be required or optional. Providing a value for the Optional Default property of a parameter instructs the designer to generate code as an optional parameter.

Parameter rows contain the following items:

  • Name

    The Name column in a parameter row displays the name of the parameter. This name is also displayed in the Name property in the Properties window. You can use this cell to change the name of any parameter with read-write permissions.

    Pointing at the parameter name displays the name of the parameter if the Name column is too narrow to show the entire name.

  • Type

    The Parameter Type cell uses Intellisense, which lets you choose from a list of all the types available in the current project or referenced projects.

  • Modifier

    The Modifier cell in a parameter row accepts and displays the new modifier of the parameter. To enter a new parameter modifier, use the drop-down list box to select from None, ref, out, or params in C#, and ByVal, ByRef, or ParamArray in VB.

  • Summary

    The Summary cell in a parameter row allows entering of code comments that appear in IntelliSense when entering the parameter into the code editor.

  • <add parameter>

    The last parameter row of a member contains the text <add parameter> in the Name cell. Clicking this cell lets you create a new parameter. For more information, see How to: Add Parameters to a Method (Class Designer).

Parameter properties in the Properties window

The Properties window displays the same parameter properties displayed in the Class Details window: Name, Type, Modifier, Summary, as well as the Optional Default property. Changing a property in one location updates the value of the property globally, including the display of its value in the other location.

Not

   To add a parameter to a delegate, see How to: Create a Member (Class Designer).

Not

   Although a destructor is a method, it cannot have parameters.

To add a parameter to a method

  1. On the diagram surface, click the type containing the method to which you want to add a parameter.

    The type obtains focus and its contents display in the Class Details window.

  2. In the Class Details window, expand the row of the method to which you want to add a parameter.

    An indented parameter row appears, containing only a pair of parentheses and the words <add parameter>.

  3. Click <add parameter>, type the name of the new parameter, and press Enter.

    The new parameter is added to the method and the method’s code. It displays in the Class Details window and the Properties window.

  4. Optionally, specify other details about the parameter, such as its type.

To add an optional parameter to a method

  1. On the diagram surface, click the type containing the method to which you want to add an optional parameter.

    The type obtains focus and its contents display in the Class Details window.

  2. In the Class Details window, expand the row of the method to which you want to add an optional parameter.

    An indented parameter row appears, containing only a pair of parentheses and the words <add parameter>.

  3. Click <add parameter>, type the name of the new parameter, and press Enter.

    The new parameter is added to the method and the method’s code. It displays in the Class Details window and the Properties window.

  4. In the Properties window, type a value for the Optional Default property. Setting a parameter's Optional Default property makes that parameter optional.

    Not

    Optional parameters must be the last parameters in the parameter list.

See Also

Tasks

How to: Modify Type Members (Class Designer)