Interface in C#.
Interface is just like a contract. Syntactically it is same with class but fundamentally it is not same with class.
Let's see an example.
As C sharp does not support multiple interface so we use interface . So interface just contains the declarations not the implementations . So in a interface we can declare the method , property and event as well. By default an interface members are public. So when a class uses the interface then class should use all the members of the interface and the class should have the function body .
So the interface can be used in two ways .
1. Implicitly.
Interface declarations :
Interface Implementations:
Instantiate Object :
2. Explicit implementations :
So in explicit implementation prefixing the interface name with method name as above. It is used mainly when class is implementing multiple interfaces or interfaces having the same name.
So this article is just providing a basic knowledge on Interface But we can explore on it in next article.
Let's see an example.
As C sharp does not support multiple interface so we use interface . So interface just contains the declarations not the implementations . So in a interface we can declare the method , property and event as well. By default an interface members are public. So when a class uses the interface then class should use all the members of the interface and the class should have the function body .
So the interface can be used in two ways .
1. Implicitly.
Interface declarations :
Interface Implementations:
Instantiate Object :
2. Explicit implementations :
So in explicit implementation prefixing the interface name with method name as above. It is used mainly when class is implementing multiple interfaces or interfaces having the same name.
So this article is just providing a basic knowledge on Interface But we can explore on it in next article.
Comments
Post a Comment