Skip to main content
A newer version of this page is available. .

Declare Parameter

  • 2 minutes to read

Purpose

Inserts an undeclared identifier to the method parameters list. Use this Code Provider inside a method to add the new parameter from the place where it was referenced.

NOTE

Declare Parameter is a cascading Code Provider. That means that the Code Provider affects all method calls and method declarations in interfaces, base and descendant classes.

Availability

Available when the caret is on an undeclared identifier name.

Usage

  1. Place the caret on the undeclared identifier.

    NOTE

    The blinking cursor shows the caret's position at which the Code Provider is available.

    public static double ConvertToUSD(double amount) {
        return amount / GetCurrencyRate(source);
    }
    static void Main(string[] args) {
        double price = ConvertToUSD(10);
    }
    
  2. Hit Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu.

  3. Use the mouse to select Declare | Declare Parameter from the menu and press Enter.

DeclareParameter

After execution, the Code Provider adds the new method parameter named after the variable and adds a dummy value of the corresponding type to each method call.

public static double ConvertToUSD(double amount, Currency source) {
    return amount / GetCurrencyRate(source);
}
static void Main(string[] args) {
    double price = ConvertToUSD(10, Currency.USD); // The first enum item was used
}
See Also