.Net > Random > Beginner Next/Skip this question

Can a structure implement an interface?

For example:

using System;

interface MyInterface
{
    void MyMethod();
    void MyMethod2();
}

public struct MyStruct : MyInterface
{
    public void MyMethod()
    {
        Console.WriteLine("MyStruct Method");
    }

    public void MyMethod2()
    {
        Console.WriteLine("MyStruct Method2");
    }
}

class MyProgram
{
    static void Main(string[] args)
    {
        MyInterface i = new MyStruct();
        i.MyMethod();
        i.MyMethod2();

        Console.ReadLine();
    }
}
Answers :
Explaination :
social share share on facebook share on twitter share on google plus share on linkedin
Add Comments :

Login

Register

Next Question