ReSharper 2024.3 Help

Complete Statement

This command inserts necessary syntax elements (parentheses, braces, semicolons and so on) and gets you in position where you can start typing the next statement.

Complete current statement

  1. Type the core of a statement (see scenarios below for examples).

  2. Press Control+Shift+Enter or choose ReSharper | Edit | Complete Statement from the main menu . Alternatively, you can press Control+Shift+A, start typing the command name in the popup, and then choose it there.

The command is helpful in numerous scenarios, including auto-closing parentheses, adding semicolons, completing if, while and for statements, and more.

For example, whenever you declare a new method, complete statement comes handy after specifying method parameters:

public void Foo(string input

At this point, to start writing the method body, you normally have to:

  • Insert a missing parenthesis.

  • Press Enter.

  • Insert an opening brace.

  • Press Enter once again.

With ReSharper, you only have to press Control+Shift+Enter, and it will automatically insert a closing parenthesis, as well as both braces, and place the caret right where you can proceed with writing the method body:

public void Foo(string input) { // the caret is here }

In similar ways, Complete Statement works with the following language constructs:

  • Types and type members: class, interface, struct, enum, delegate, field, event, and method declarations.

  • Statements: if, while, do, switch, using, lock, continue, break, and return statements; case and default clauses; conversion of single-line statements to block statements.

  • Expressions: invocation, element access, string/char literals; object, member, and collection item initializers; expressions that create anonymous types and implicitly typed arrays.

Below, you can find a number of examples of applying the complete statement command in different contexts.

Use case

Before Complete Statement

After Complete Statement

Class declaration

public class Foo/*caret*/
public class Foo { /*caret*/ }

Delegate declaration

delegate void ChangeHandler(object sender/*caret*/
internal delegate void ChangeHandler(object sender); /*caret*/

Nested method invocation

myVar.DoSomething(foo.Bar(value/*caret*/
myVar.DoSomething(foo.Bar(value)); /*caret*/

if statement

if(myVar != null/*caret*/
if(myVar != null) { /*caret*/ }

case clause

switch (position) { case Position.Last/*caret*/ }
switch (position) { case Position.Last: /*caret*/ }

Conversion of a single-line statement into block (case A)

if(myVar != null) position = Position.Last;/*caret*/
if(myVar != null) { position = Position.Last; /*caret*/ }

Conversion of a single-line statement into block (case B)

if(myVar != null) /*caret*/position = Position.Last;
if(myVar != null) { /*caret*/ position = Position.Last; }

Element access expression

var myValues = new Value[10/*caret*/
var myValues = new Value[10]; /*caret*/

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the ReSharper by language section.

Last modified: 23 September 2024