From the course: C#: Interfaces and Generics
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Using explicit interface implementation - C# Tutorial
From the course: C#: Interfaces and Generics
Using explicit interface implementation
- [Instructor] In the previous example, we saw how to implement multiple interfaces on a single C# class, and how that feature can help overcome the limitation that C# places on class inheritance. However, the question arises, what happens when two separate interfaces define the same method? So, to solve this problem, you need to use explicit interface implementation, which I'll demonstrate in this example. So in our editor, in chapter two, example five, I'm going to open the explicit interfaces folder, and open the program code. And when I do that, you can see that I have a couple of interfaces defined, Intf1 and Intf2. They both define the same method. And I have a class called InterfaceTest, and that also defines a SomeMethod, which just writes out something to the console. And what we're going to do is add both of the interfaces to this test class. All right, so we'll add Intf1 and Intf2. Okay, so now that I've added those interfaces, I have to implement the SomeMethod of each of…
Contents
-
-
-
-
(Locked)
Understanding C# interfaces2m 46s
-
(Locked)
Defining and implementing an interface6m 24s
-
(Locked)
Interfaces and casting4m 22s
-
(Locked)
Implementing multiple interfaces4m 1s
-
(Locked)
Using explicit interface implementation4m 9s
-
(Locked)
Using .NET-defined interfaces7m 43s
-
(Locked)
Challenge: Programming C# interfaces2m 24s
-
(Locked)
Solution: Programming C# interfaces2m 49s
-
(Locked)
-
-