Saturday 11 April 2015

Interface Concept of C# dotnet

Hello Friends,
                                Now I am going to describe the Concept of Interface in C# dot net.Interface is a identical with pure abstract class but advantages of Interface is that multiple interfaces can be implimented.
                 Using this concept We can also invoke the functions from different classes through the same Interface reference.
               It declared by Iterface keyword and deafult behavier of Interface is Public.

Ex:

using System;

namespace Interfaceprog
{
interface myinterfaceA
{
void myfirstinter();
void mysecondinter (string s);
}
interface myinterfaceB
{
void mythirdinter(int i,int j);
}
class myinterface:myinterfaceA,myinterfaceB
{
public void myfirstinter()
{
Console.WriteLine ("I am member of myinterfaceA class....");
}
public void mysecondinter (string s)
{
Console.WriteLine ("My Length is:"+s.Length);
}
public void mythirdinter(int i,int j)
{
Console.WriteLine ("My value is:"+i*j);
}

}
class MainClass
{
public static void Main (string[] args)
{
myinterface obj = new myinterface ();
obj.myfirstinter ();
obj.mysecondinter ("Rabi");
obj.mythirdinter (75,55);

}
}

}



Output:
I am member of myinterfaceA class....
My Length is:4
My value is:4125

Thanks & Regard
Rabi

No comments:

Post a Comment