This command filters the list of types, methods, and variables to match the expected type of an expression. It works anywhere as long as ReSharper can determine the expected type of the expression, for example, right-hand sides of assignments, variable initializers, or return statements. If several return types are possible, ReSharper detects the most recently used symbol of an applicable type and automatically selects it in the lookup list. Smart Completion can also suggest creating anonymous delegates, lambda expressions, and regular methods, as well as local variables for out parameters. In addition to that, in object initializers, Smart Completion suggests fields/properties that were not yet assigned a value.
By default, smart completion items are included in the suggestion lists of automatic and basic completion. If you want to change the default behavior, use the corresponding controls on the page of ReSharper options.
To invoke smart completion
Place the caret at the position where you're going to type your code.
- Select a suggestion from the list and press Enter or start typing the initial letters of the identifier or its CamelHumps abbreviation to narrow down the list of suggestions.
You can also invoke smart completion on an existing identifier. In this case, there are two ways to apply the selected completion suggestion; press Enter to insert it and leave the existing item or press Tab to replace the existing item (If necessary, you can change the default shortcuts on the page of ReSharper options).
Examples of smart completion
You can use the following examples to get an idea of how smart completion works with various code items:
After a return statement
In the right-hand side of assignments
In cast expressions
Before: After launching Smart Completion (since there's a single option in this case, ReSharper inserts the expected type without displaying a drop-down list):
In object initializers
ReSharper provides Smart Completion for setting properties in object initializers that were not previously set for a particular object:
In lambda expressions
In addition to traditional anonymous and named methods, Smart Completion readily generates lambda-expression syntax:
Creating a local variable in place of an out parameter
This feature is supported in the following languages and technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.