Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call MyFunction of interface. How will i do that ?
Also i want to know what MyInterface.MyFunction() do ?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2
{
    interface MyInterface
    {
        void MyFunction();
    }

    abstract public class MyAbstractClass
    {
        abstract public void MyFunction();
    }

    public class MyClass : MyAbstractClass, MyInterface
    {
        public override void MyFunction()
        {
            Console.WriteLine("A");
        }

        void MyInterface.MyFunction()
        {
            Console.WriteLine("B");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            MyClass mc = new MyClass();
            mc.MyFunction();

        }
    }
}
Posted
Updated 9-Jul-14 0:53am
v2
Comments
jo.him1988 9-Jul-14 6:54am    
try this
MyInterface mm = new MyClass();
mm.MyFunction();

or

MyInterface myInterFace = mc;
myInterFace.MyFunction();
Deepanshu Goel 9-Jul-14 6:57am    
thanks :)

1 solution

Explicitly implemented members can only be called with an instance of the interface. They do not form part of the Class's API.

C#
MyInterface i = new MyClass();
i.MyFunction();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900