I would like to know in general, but this question came up when I was trying to use IWMPMedia (http://msdn.microsoft.com/en-us/library/dd563397(v=vs.85).aspx) which is an Interface. I was unab开发者_开发百科le to use it in the normal object sense where I could instantiate it with the "new" keyword.
IWMPMedia is a COM interface. You get its declaration by adding a reference to c:\windows\system32\wmp.dll
COM interfaces don't behave very much like C# interfaces. You can never create an instance of a C# interface with the new keyword. But you can with a COM interface. But not IWMPMedia, you get an instance of it by using one of the other interface methods. Like IWMPPlayList.Item or IWMPCore.currentMedia. The programming guide for Windows Media Player is available here.
An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.
Reference: MSDN C# Programming Guide.
An interface is a contract that a class may implement. This contract will define certain properties/ methods that all classes implementing that interface must contain.
精彩评论