Тёмный
No video :(

How to Implement Two interfaces with Same Method Signature in C# 

Brian Lagunas
Подписаться 18 тыс.
Просмотров 4,5 тыс.
50% 1

In this video, I answer the question, "How to Implement Two interfaces with Same Method Signature in C#?".
It is very common to have a class that implement two interfaces which have the same method signature. Or maybe, you implement an interface that has the same method signature as a method on your class. Either way, the result is a conflict in the method implementations. By default, you can only have one unique method signature defined in a class. However, when working with interfaces you can use a special implementation of interfaces to get around that limitation.
Explicit implementation of interfaces allows you to provide unique implementations for for each interface method.
Explicit implementations of interfaces are actually used to solve two problems.
- Hide the implementation of an API from the public
- Resolve conflicting method signatures
Using an explicit interface implementation is as easy as changing the scope of the method to private, and appending the interface name to the method signature.
For example, consider this interface implementation
public interface IMyInterface
{
void DoSomething();
}
The class that implements the interface would look something like:
public class MyClass : IMyInterface
{
public void DoSomething() { ... }
}
To implement the interface explicitly use:
public class MyClass : IMyInterface
{
void IMyInterface.DoSomething() { ... }
}
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
pluralsight.px...
Sponsor Me:
github.com/spo...
Follow Me:
Twitter: / brianlagunas
Twitch: / brianlagunas
Blog: brianlagunas.com
GitHub: github.com/bri...

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 52   
@shiprasingh7759
@shiprasingh7759 3 года назад
Oh my my.. I m a .net developer from more than 2 years now. And I thought it's not possible... Thanks a bunch!
@BrianLagunas
@BrianLagunas 3 года назад
Glad I could help
@VinuP2023
@VinuP2023 4 года назад
Thank you Brian A request video: when to use interface and abstract class with real time example 🙂
@BrianLagunas
@BrianLagunas 4 года назад
Great suggestion!
@beautifulheartsoothingreci28
@beautifulheartsoothingreci28 4 года назад
@@BrianLagunas Yes absolutely please! I've been working with C# for a while now yet I still don't know really when to use which.
@jitendrasonkar8240
@jitendrasonkar8240 Год назад
very nice , i am from inida.
@BrianLagunas
@BrianLagunas Год назад
Hello there. Thanks for watching from India.
@Tamer_Ali
@Tamer_Ali 4 года назад
Amazing as usual
@BrianLagunas
@BrianLagunas 4 года назад
Thank you so much 😀
@EngDuraid
@EngDuraid 4 года назад
Thank you Very mush ,can you please create a video talks about the best way to execute a commad from event using MVVM ,
@BrianLagunas
@BrianLagunas 4 года назад
Sure, I could probably do that using the Microsoft behaviors.
@EngDuraid
@EngDuraid 4 года назад
Thank you , ill be waiting ...
@julianturner6203
@julianturner6203 4 года назад
Great content Brian, thanks 😁
@BrianLagunas
@BrianLagunas 4 года назад
Glad you enjoyed it
@tusharparab9866
@tusharparab9866 4 года назад
First comment.... We can also write like.. IMetric metric_obj = obj; metric_obj.Calculate();
@BrianLagunas
@BrianLagunas 4 года назад
Winner winner! You rock!
@BrianLagunas
@BrianLagunas 4 года назад
Yes, that a great point. I am so used to working with interfaces, I usually never have the object instance like in the sample. So I am always having to cast one interface to another. It's just habit now 😂
@JohnPeter-yf5jf
@JohnPeter-yf5jf 4 года назад
When you need it and nothing else about it.
@prabhakaranvelliangiri9655
@prabhakaranvelliangiri9655 4 года назад
@@BrianLagunas so we can consider that is way towards good approach?
@VinuP2023
@VinuP2023 4 года назад
Hello Brian, a request video please: use of partial class in a real time scenario. I know partial classes are there in code behind of Win forms and WPF XAML, but do we ever need to create a partial class for some use case.
@BrianLagunas
@BrianLagunas 4 года назад
Great suggestion!
@gkmishra2009
@gkmishra2009 4 года назад
synchronous and asynchronous encryption?
@gkmishra2009
@gkmishra2009 4 года назад
Diff between Innumerable and Ienumerater
@prabhakaranvelliangiri9655
@prabhakaranvelliangiri9655 4 года назад
Awesome Missed this time to comment as first 😭
@BrianLagunas
@BrianLagunas 4 года назад
Thanks for watching!
@prabhakaranvelliangiri9655
@prabhakaranvelliangiri9655 4 года назад
@@BrianLagunas I missed enum binding it's awesome never did that kind of binding. 🔥🙏
@prabhakaranvelliangiri9655
@prabhakaranvelliangiri9655 4 года назад
@@BrianLagunas how to loads content control in user control and how to perform navigation in same content control
@longuinni
@longuinni 4 года назад
That new for me. I would change the "Calculate()" to "CalculateMetric()" and "CalculateImperial()" inside the interfaces. I have another suggestion, how to implement INotifyDataErrorInfo with complex objects , validate the properties and display the errors for each property inside that complex object.
@BrianLagunas
@BrianLagunas 4 года назад
Keep in mind, this was just an example of implementing interfaces explicitly, and is demo code 😁. A more real world example is if you have a custom collection with an indexer, but derive from something like IList which also has an indexer. You want to hide the ILIst indexer and use yours instead.
@gkmishra2009
@gkmishra2009 4 года назад
Performance testing of API?
@gkmishra2009
@gkmishra2009 4 года назад
Hierrachical Dependency Injection
@gkmishra2009
@gkmishra2009 4 года назад
benefits of abstract class over normal class benefits of using interfaces?
@Tamer_Ali
@Tamer_Ali 4 года назад
Hi Brian, 1- What is the best practice to send hundreds of emails via email service without blocking the UI thread? 2- Do you recommend to create a console app (as an email Queue ) for it and use windows Task Scheduler to call it every a few minutes to checked if there are new emails to send them? Thanks
@BrianLagunas
@BrianLagunas 4 года назад
This really depends on a number of variables. From app requirements, to the email server limits, and more. This is not really something that is easily answered in a comment. I would just use a paid service and call it done 😁
@gkmishra2009
@gkmishra2009 4 года назад
How we use oauth2. 0 in api
@saroshwadia
@saroshwadia 4 года назад
Here is a XF use case: Have a MainView with a ListView on ItemSelected -> PushModalAsync(passing the selected item to the DetailView) in the DetailView have a Customer picklist (amongst other pick lists, datepickers etc.) and a button to Add New Customer which in turn does another PushModalAsync.. to open the AddCustomerView. Once the user fills in the required data and clicks "OK" need to return to the DetailView with the new Customer info and the Customer picklist needs to be updated and that new customer should be selected in the Customer picklist. How best can we do this using MVVM and Prism?
@BrianLagunas
@BrianLagunas 4 года назад
That's so easy with Prism. First off, you need to drop the model push and use a navigationpage instead. You can hide the nave bar if you want. the rest is just basic logic and navigation. you can pass parameters during navigation when going forward or back.
@saroshwadia
@saroshwadia 4 года назад
@@BrianLagunas Just starting with Prism - So the MainView will be a Nav page right? and what events do I need to use to send and receive parameters as objects? Thx
@BrianLagunas
@BrianLagunas 4 года назад
@@saroshwadia check this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-inxl6Xfqsjs.html
@saroshwadia
@saroshwadia 4 года назад
@@BrianLagunas Thx
@gkmishra2009
@gkmishra2009 4 года назад
what is bearer Token
@gkmishra2009
@gkmishra2009 4 года назад
how do encryption in our application?
@BrianLagunas
@BrianLagunas 4 года назад
Wow... that's a lot of questions. Thanks for asking.
@gkmishra2009
@gkmishra2009 4 года назад
how we implement abstraction in application what is polymorphism real life example of method overriding real life example of abstraction how you know it is abstracted? --------mvc------------------- how enable cookie in mvc share data across 2 view? partial view? how pass model in partial view can a partial view have a model? how consume partialview? how invoke partial view?
@blackdream9372
@blackdream9372 2 года назад
Here is the way to implement such interfaces internal class Program { static void Main(string[] args) { IProbably probl = new Impliment(); probl.Save("hello"); Console.Read(); } } class Impliment : IProbably, ISave { void IProbably.Save(string name) { Console.WriteLine("Probably"); } void ISave.Save(string name) { Console.WriteLine("Saves"); } } interface IProbably { void Save(string name); } interface ISave { void Save(string name); }
@gkmishra2009
@gkmishra2009 4 года назад
token based authentication
@gkmishra2009
@gkmishra2009 4 года назад
Diff between soap and rest
@gkmishra2009
@gkmishra2009 4 года назад
where we use abstract class instead of interface can we declare property in interface? in abstract class can we create constructor why we create constructor in abstract class extension method can we use any static method as extension method? diff between static method and extension method can we have static method in normal method can we have normal method in static class yield keyword anonymous type diff delegate and normal method what is benefit to call a method via delegate? delegate is stack or heap memory? does method take any memory? delegate taking memory for function? function take memory? where function take memory? one interface and 2 class implement that interface how register this in startup.cs in .net core? in this scene you use add.scoped? if this interface has one method and both class has its implementation then which class method invoke first if we call interface method? property injection what is IapplicationBuilder in .net core app.use and app.run? diff between async and await? use of private cons in singlton class? static class and singleton diff? where we use static class? where we use simglton class? default return type of the web api? how user can get return type in all format? new thing in sql server 2017 magic table? Rank and Dense Rank?
@BrianLagunas
@BrianLagunas 4 года назад
and they just keep coming 😁
@gkmishra2009
@gkmishra2009 4 года назад
Active Directory in .net
Далее
How to Bind an Enum to a ComboBox in WPF
6:11
Просмотров 18 тыс.
C# Yield Return: What is it and how does it work?
15:09
Oh No! My Doll Fell In The Dirt🤧💩
00:17
Просмотров 3,7 млн
WPF in C# with MVVM using Caliburn Micro
1:23:30
Просмотров 363 тыс.
Task vs ValueTask: When Should I use ValueTask?
10:43
Naming Things in Code
7:25
Просмотров 2,1 млн
Which do I use, ConfigureAwait True or False?
6:53
Просмотров 37 тыс.
Brutally honest advice for new .NET Web Developers
7:19