- What is an interface?
- Where can we use an interface?
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.
A very nice article here:
http://www.codeproject.com/Articles/18743/Interfaces-in-C-For-Beginners
Properties
Of Interface:-
- Supports multiple inheritance (Single Class can implement multiple interfaces).
- Contains only incomplete method.
- Cannot Contains data members.
- By Default interface members is public (We Can not set any access modifier into interface members).
- Interface cannot contain constructors.
interface IApp
{
int Sum(int i, int j); //By Default Public
}
class
App : IApp
{
// Can use either this way
public int
sum(int i, int
j) //Must be declare Public
{
return i + j;
}
// Second method
int IApp.sum(int i, int j) //No need to declare Public
int IApp.sum(int i, int j) //No need to declare Public
{
return i + j;
}
}
No comments:
Post a Comment