16

Previously in Visual Studio, if you declared a class with an interface you could put your cursor on the interface, right-click it and select Implement Interface. (See here for a similar question for VS 2008.)

I've started working on a project that has defined numerous interfaces that will be used with SimpleInjector. Now, as I am beginning to write my service classes, I've noticed that the Implement Interface menu option is gone.

How can I implement all necessary method stubs like I could in VS 2008?

Sorry if this is a duplicate, however, I couldn't find this answer anywhere.


EDIT NOTES - Aug 17, 2018

This has been a hot question over the years. I've updated the title and tags for this so that it covers all pertinent versions of C# and Visual Studio.

This was ultimately a coder FAIL on my part. Much like classes, interfaces when generated by VS aren't defined as public. You will have to manually modify the interface declaration with the public accessor since VS doesn't automatically add it. It's easy to forget this step because you don't have to set member modifiers within the interface since, by definition, they will all be public.

4
  • msdn.microsoft.com/en-us/library/tx1s9z1w.aspx it seems to be still there Commented Jul 24, 2013 at 20:27
  • FYI, this feature also exists in VS2010. I haven't actually tried using it in VS2012 as I normally don't leverage that feature too often, so I can't comment if it's there or not. But in my experience, if you have other compile errors in your code at the same time, or missing relevant assembly references, sometimes options like that don't appear because it can't figure out what it is or what you're doing. Commented Jul 24, 2013 at 20:27
  • 1
    Works for me, as always. The "Implement interface" is the first menu item in the context menu available when you right click the interface name. VS2012 for sure. Commented Jul 24, 2013 at 20:27
  • I want to implement IComparable interface in 2010 VS and still doesn't show me the blue tag... Darn thing! When debug no errors either. What am I missing here? Found the issue. There are two types of interfaces. One for type-safe using Generics and the other for non-type safe. I had to use type-safe to see the blue tag. But I am doubtful, why is that so? Commented May 14, 2014 at 23:55

3 Answers 3

11

That hasn't changed. All you need to do is hover over the interface name in the class, and the blue underline bar should show up, giving you options to implement the interface. If the blue underline is not appearing, check to make sure the interface is accessible with what assemblies and namespaces you are referencing.

Sign up to request clarification or add additional context in comments.

4 Comments

Ah, fail on my part. This was occurring due to a mistake I made when I defined the interface. I wasn't getting any warnings from Intellisense. I fixed the interface and the drop-down option from the interface declaration appeared.
@RLH: Can I take a guess? public class IMyInterfaceIAccidentallyDeclaredAsAClass { }?
Yup. I always get the declaration skewed. The interface must be defined as public, the methods have no public/private declaration.
The "blue line" may (VS 2013) appear under the class name (and not under the interface) but you can still right-click the Interface and choose implement - it works just the same
10

When you look at the interface name, you should see a little blue underline:

first image

If you hover over it, a drop down menu will appear, letting you implement the interface:

second image

Comments

9

Put your cursor somewhere in the interface text (the part after the colon) and hit Ctrl + .

1 Comment

Perfect! Intellisense decided to leave the building on my machines recently but this still works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.