Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This code generation applies to:
C#
Visual Basic
What: Lets you immediately generate a local variable to replace an existing expression.
When: You have code which could be easily reused later if it were in a local variable.
Why: You could copy and paste the code multiple times to use it in various locations, however it would be better to perform the operation once, store the result in a local variable, and use the local variable throughout.
Highlight the expression that you want to assign to a new local variable.
C#:
Visual Basic:
Next, do one of the following:
Select Introduce local for (all occurrences) of 'expression' from the drop-down menu.
Tip
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made before making your selection.
The local variable is created, with the type inferred from its usage. Give the new local variable a new name.
C#:
Visual Basic:
Note
You can use the ...all occurrences of... menu option to replace every instance of the selected expression, not just the one you have specifically highlighted.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today