Gerar um método no Visual StudioGenerate a method in Visual Studio
Esta geração de código aplica-se a:This code generation applies to:
C#C#
Visual BasicVisual Basic
O quê: permite que você adicione imediatamente um método a uma classe.What: Lets you immediately add a method to a class.
Quando: você introduz um novo método e deseja declará-lo correta e automaticamente.When: You introduce a new method and want to properly declare it, automatically.
Por quê: você poderia declarar o método e os parâmetros antes de usá-los; no entanto, esse recurso gerará a declaração automaticamente.Why: You could declare the method and parameters before using it, however this feature will generate the declaration automatically.
Como fazerHow-to
Coloque o cursor na linha em que há um rabisco vermelho.Place your cursor on the line where there is a red squiggle. O rabisco vermelho indica um método que ainda não existe.The red squiggle indicates a method that doesn't exist yet.
C#:C#:
Visual Basic:Visual Basic:
Depois, siga um destes procedimentos:Next, do one of the following:
TecladoKeyboard
- Pressione Ctrl + .Press Ctrl+. para acionar o menu Ações e Refatorações Rápidas.to trigger the Quick Actions and Refactorings menu.
MouseMouse
- Clique com o botão direito do mouse e selecione o menu Ações Rápidas e Refatorações.Right-click and select the Quick Actions and Refactorings menu.
- Passe o mouse sobre o rabisco vermelho e clique no ícone deHover over the red squiggle and click the
ícone que aparece.icon that appears.
- Clique no íconeClick the
ícone que aparece na margem esquerda quando o cursor de texto já está na linha com o rabisco vermelho.icon that appears in the left margin if the text cursor is already on the line with the red squiggle.
Selecione Gerar método no menu suspenso.Select Generate method from the drop-down menu.
Dica
Use o link Visualizar alterações na parte inferior da janela de visualização para ver todas as alterações que serão feitas antes de fazer sua seleção.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.
O método é criado com os parâmetros inferidos com base em seu uso.The method is created with any parameters inferred from its usage.
C#:C#:
Visual Basic:Visual Basic: