Call (Consume) Interface function (method) in main method of Console Application

Last Reply 16 days ago By dharmendr

Posted 16 days ago

i am using existing database layer of one project in console application. i want to call interface function in main method of console application.

interface function is define in database.cs class.

so i am writting like this

class program {
    public void main()
    {
        interfaceclass i=null;
        i.testmethod();
    }
}

 

You are viewing reply posted by: dharmendr 16 days ago.
Posted 16 days ago

Hi mohal92,

Check this example. Now please take its reference and correct your code.

Interface

C#

public interface IInterfaceClass
{
    void testmethod();
}

VB.Net

Public Interface IInterfaceClass
    Sub testmethod()
End Interface

Code

C#

class Program
{
    static void Main(string[] args)
    {
        ImplementInterface implement = new ImplementInterface();
        implement.testmethod();
    }
}

class ImplementInterface : IInterfaceClass
{
    public void testmethod()
    {
        Console.WriteLine("Intercace called");
        Console.ReadLine();
    }
}

VB.Net

Module Module1

    Sub Main()
        Dim implement As ImplementInterface = New ImplementInterface()
        implement.testmethod()
    End Sub

    Class ImplementInterface : Implements IInterfaceClass
        Public Sub testmethod() Implements IInterfaceClass.testmethod
            Console.WriteLine("Intercace called")
            Console.ReadLine()
        End Sub
    End Class
End Module

Screenshot