
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implicit Implementation of the Interface in C#
C# interface members can be implemented explicitly or implicitly.
Implicit implementations don't include the name of the interface being implemented before the member name, so the compiler infers this. The members will be exposed as public and will be accessible when the object is cast as the concrete type.
The call of the method is also not different. Just create an object of the class and invoke it.
Implicit interface cannot be used if there is same method name declared in multiple interfaces
Example
interface ICar { void displayCar(); } interface IBike { void displayBike(); } class ShowRoom : ICar, IBike { public void displayCar() { throw new NotImplementedException(); } public void displayBike() { throw new NotImplementedException(); } } class Program { static void Main() { ICar car = new ShowRoom(); IBike bike = new ShowRoom(); Console.ReadKey(); } }
Advertisements