Skip to main content

Add Parameter

  • 2 minutes to read

Adds a new parameter to a method.

Add Parameter is a cascading refactoring. That is, the refactoring affects all method calls and method declarations in interfaces, base and descendant classes. For instance, if you apply the refactoring to the method declaration within an interface, it also changes the appropriate method declarations in all implementors and all calls to these methods.

#Purpose

This refactoring is useful when you need to quickly add a new parameter to an existing method.

#Availability

From the context menus or via shortcuts:

  • when the caret is inside method parameters within a method declaration or call.

Note

The refactoring is available for method declarations in interfaces, base and descendant classes as well as for the declaration in the current class.

#Notes

  • This refactoring enables Text Fields to make it easier for you to type the parameter type and name.
  • Once you’ve finished entering the parameter type and name, each method call is updated with a new parameter. An empty value corresponding to the specified type is used by default (0 for integer, String.Empty for string, etc.).
  • Automatically created Navigation Links allow you to easily navigate through all method calls and change default parameter values.
  • A Marker is dropped at a parameter declaration statement. This allows you to easily get back to the method declaration when you are done with parameter values.

#Example

public class TestClass
{
    private static int AddValues(int x)
    {
        return x;
    }
    private void TestMethod()
    {
        int res = AddValues(10);
    }
}

Result:

public class TestClass
{
    private static int AddValues(int x, int y)
    {
        return x;
    }
    private void TestMethod()
    {
        int res = AddValues(10, 0);
    }
}

#Animation

rsAddParameterCSharp

See Also