Sunday, December 7, 2008

Multiple Interfaces

Example:

namespace ConsoleApplication7
{
interface Example
{
void Show(); //Method declaration
}
interface Test
{
void Display(); //Method declaration
}
class Program1:Test,Example
{
void Test.Display() //Method Definition
{
Console.WriteLine("Hi from Test Interface");
Console.ReadLine();
}
void Example.Show() //Method Definition
{
Console.WriteLine("Hello from Example Interface");
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
Program1 pgm1 = new Program1();
Test t = (Test)pgm1;//Instance declaration
t.Display(); //Calling the method
Example ex = (Example)pgm1;//Instance declaration
ex.Show(); //Calling the method
}
}
}

No comments: