Thank you. I don't know if this is worthy of another thread or not,
but I got this code from
http://www.csharp-station.com/Tutorials/Lesson13.aspx
class InterfaceImplementer : IMyInterface
{
static void Main()
{
InterfaceImplementer iImp = new InterfaceImplementer();
iImp.MethodToImplement();
}
public void MethodToImplement()
{
Console.WriteLine("MethodToImplement() called.");
}
}
I just wanted to know why this line was there:
InterfaceImplementer iImp = new InterfaceImplementer();
Why does he have to instantiate the class if he's already in the class?
Thanks again.
Nicholas Paldino [.NET/C# MVP] wrote:
You are right. If a class says that it implements an interface, then it
must, by definition, implement ALL members of the interface. The C#
compiler will not allow the program to compile otherwise.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<ne***********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
Just learning about interfaces and had a probably simple question.
If a class inherits from an Interface, does this guarantee that the
class will have the methods defined in the Interface? I know this is
supposed to be true from what I read, but what I'm really asking is
that if a class implements an interface and it does not somewhere in
that class implement the methods, properties, etc. (all of them) in
that class, will that cause the program to not compile? Somewhere in
my class I have to have a reference to all the methods of the
Interface, right?
Thank you for any help.