Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Selonke
10,323 PointsWhy are there methods with definitions for interfaces in MSDN?
In the MSDN's definition for the ISet<T> interface. https://msdn.microsoft.com/en-us/library/dd412081.aspx Here is a list of Definitions for the properties, methods, and extension methods for this interface.
There first method is ISet<T>.Add Method (T). https://msdn.microsoft.com/en-us/library/dd412075.aspx
I'm trying to understand why there are methods with definitions for this interface? I would understand this fully if it was a class, but interfaces (as far as I understand) do not have method's with bodies. How, for example, should we be able to implement the ISet<T>.Add method. As an interface, this method should only be a method signature, and not a fully defined method. How do we get to use all of these useful methods just by implementing an interface, where is the code/logic for these methods? They are not in the interface, because the interface merely has a method signature.
It looks like the MDSN treats the documentation of Interfaces the same as Classes...
1 Answer
Steven Parker
231,210 PointsThe interface definitions are just for the signature and intended functionality.
The definition might look a bit like it might be for a class, but it's not quite the same. Compare the definitions for the ISet<T>.Add Method with the HashSet<T>.Add Method.
Notice that the latter has an access specifier ("public
"), but the interface definition does not. Also the class method definition has usage remarks and examples.