0

Just came across a code where a method with the same name is implemented within the class twice. Once with the name only Second with the Interface name and then the method name. What is the concept called? I am unable to find the right direction. And if someone can explain it that would be great.

    // Online C# Editor for free
// Write, Edit and Run your C# code using C# Online Compiler

using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        var obj = new AuthClass();
        Console.WriteLine(obj.Login());
        var obj2 = new AuthClass() as IAuth;
        Console.WriteLine(obj2.Login());
        //------------
    }
}

public class AuthClass : IAuth 
{
    public string Login()
    {
        return "Method : You can be a developer";
    }
    string IAuth.Login()
    {
        return "Interface: Please learn the concepts";
    }
}
public interface IAuth 
{
    string Login(); 
}
hellowahab
  • 2,445
  • 4
  • 21
  • 34
  • 2
    `InterfaceName.Method` this is called Explicit implementation of interface methods. – Chetan Sep 15 '22 at 06:12
  • 2
    https://stackoverflow.com/questions/9195562/implement-interface-vs-implement-interface-explicitly-in-c-sharp – Chetan Sep 15 '22 at 06:12
  • Or [Explicit interface implementation](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation) – JonasH Sep 15 '22 at 06:53
  • Does this answer your question? [C# Interfaces. Implicit implementation versus Explicit implementation](https://stackoverflow.com/questions/143405/c-sharp-interfaces-implicit-implementation-versus-explicit-implementation) – Progman Sep 15 '22 at 12:15

0 Answers0