C
C#4mo ago
HiveMind

Can't access interface method

I have an interface with a defined method - RegisterLanguageChange, but I can't use it in the class that implements the interface. Although I can use ChangeLanguageVersion. Why?
C#
internal interface ILanguageChanged
{
protected void RegisterLanguageChange()
{
MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
mainWindow.LanguageChanged += this.ChangeLanguageVersion;
}

protected void ChangeLanguageVersion(string language);
}
C#
internal interface ILanguageChanged
{
protected void RegisterLanguageChange()
{
MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
mainWindow.LanguageChanged += this.ChangeLanguageVersion;
}

protected void ChangeLanguageVersion(string language);
}
No description
3 Replies
Sossenbinder
Sossenbinder4mo ago
The main problem (aside from the visibilitiy) in your case is that you are using default interface implementations, which behave a bit different You'd have to cast this to the actual interface
Sossenbinder
Sossenbinder4mo ago
Andrew Lock | .NET Escapades
Understanding C# 8 default interface methods
In this post I provide an introduction to default interface methods, how they work at a high level, their typical uses, and some of their sharp edges
Angius
Angius4mo ago
Ideally, avoid implementation in interfaces. It was added as a tool to help with refactoring more than anything else, and should not be reached for as the default solution.
Want results from more Discord servers?
Add your server