How to implement an interface in a class in C#? - Biz Tech

How to implement an interface in a class in C#?

Listen
public interface IMyInterface
{
    void Method1();
    int Method2(string parameter);
}

public class MyClass : IMyInterface
{
    public void Method1()
    {
        Console.WriteLine("Method1 called.");
    }

    public int Method2(string parameter)
    {
        Console.WriteLine("Method2 called with parameter: " + parameter);
        return 42;
    }
}

MyClass myObject = new MyClass();
myObject.Method1();
int result = myObject.Method2("hello");
Console.WriteLine(result);