Implement an interface in Visual Studio
This code generation applies to:
What: Lets you immediately generate the code required to implement an interface.
When: You want to inherit from an interface.
Why: You could manually implement all interface one-by-one, however this feature will generate all method signatures automatically.
Place your cursor on the line where there is a red squiggle that indicates you have referenced an interface, but have not implemented all required members.
Next, do one of the following:
- Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
- Right-click and select the Quick Actions and Refactorings menu.
- Hover over the red squiggle and click the icon that appears.
- Click the icon that appears in the left margin if the text cursor is already on the line with the red squiggle.
Select Implement interface from the drop-down menu.
- 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.
- Use the Document, Project, and Solution links at the bottom of the preview window to create the proper method signatures across multiple classes that implement the interface.
The interface's method signatures is created, and is ready to be implemented.
(C# only) Use the Implement interface explicitly option to preface each generated method with the interface name to avoid name collisions.