Home > Backend Development > C#.Net Tutorial > What is implicit implementation of interfaces and when to use implicit implementation of interfaces in C#?

What is implicit implementation of interfaces and when to use implicit implementation of interfaces in C#?

WBOY
Release: 2023-09-11 22:17:06
forward
1001 people have browsed it

什么是接口的隐式实现以及何时在 C# 中使用接口的隐式实现?

C# Interface members can be implemented explicitly or implicitly.

Implicit implementation does not include the name of the interface being implemented before the member name, so the compiler infers this. These members will be exposed as public and accessible when the object is converted to a concrete type. The invocation of the

method is no different. Just create an object of this class and call it.

If the same method name is declared in multiple interfaces, you cannot use an implicit interface

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();
   }
}
Copy after login

The above is the detailed content of What is implicit implementation of interfaces and when to use implicit implementation of interfaces in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template