Reorder Parameters Refactoring (C#)
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Reorder Parameters
is a Visual C# refactoring operation that provides an easy way to change the order of the parameters for methods, indexers, and delegates. Reorder Parameters
changes the declaration, and at any locations where the member is called, the parameters are rearranged to reflect the new order.
To perform the Reorder Parameters
operation, put the cursor on or next to a method, indexer, or delegate. When the cursor is in position, invoke the Reorder Parameters
operation by pressing the keyboard shortcut, or by clicking the command from the shortcut menu.
Note
You cannot reorder the first parameter in an extension method.
To reorder parameters
Create a class library named
ReorderParameters
, and then replaceClass1
with the following example code.class ProtoClassA { // Invoke on 'MethodB'. public void MethodB(int i, bool b) { } } class ProtoClassC { void D() { ProtoClassA MyClassA = new ProtoClassA(); // Invoke on 'MethodB'. MyClassA.MethodB(0, false); } }
Place the cursor on
MethodB
, either in the method declaration or the method call.On the Refactor menu, click Reorder Parameters.
The Reorder Parameters dialog box appears.
In the Reorder Parameters dialog box, select
int i
in the Parameters list, and then click the down button.Alternatively, you can drag
int i
afterbool b
in the Parameters list.In the Reorder Parameters dialog box, click OK.
If the Preview reference changes option is selected in the Reorder Parameters dialog box, the Preview Changes - Reorder Parameters dialog box will appear. It provides a preview of the changes in the parameter list for
MethodB
in both the signature and the method call.If the Preview Changes - Reorder Parameters dialog box appears, click Apply.
In this example, the method declaration and all the method call sites for
MethodB
are updated.
Remarks
You can reorder parameters from a method declaration or a method call. Position the cursor on or next to the method or delegate declaration but not in the body.