Social Icons

Saturday, 8 March 2014

C# Program to implement a Interface property

Way 1-

using System;
namespace ConsoleApplication7
{
    interface I1
    {
        void myfunction();
    }

    interface I2
    {
        void myfunction();
    }

    class test : I1, I2
    {
        public void myfunction()
        {
            Console.WriteLine("guess which interface I represent??");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            test t = new test();
            I1 i1 = (I1)t;
            i1.myfunction();
            I2 i2 = (I2)t;
            i2.myfunction();
            Console.ReadLine();
        }
    }
}

                                                                  Output




Way 2-

using System;
namespace ConsoleApplication11
{
    interface I1
    {
        void myfunction();
    }

    interface I2
    {
        void myfunction();
    }

    class test : I1, I2
    {
        void I1.myfunction()
        {
            Console.WriteLine("Now i can say this here is I1 implimented");
        }
        void I2.myfunction()
        {
            Console.WriteLine("now i can say this here is I2 implemented");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            test t = new test();
            I1 i1 = (I1)t;
            i1.myfunction();
            I2 i2 = (I2)t;
            i2.myfunction();

            Console.ReadLine();
        }
    }
}


                               Output

No comments:

Post a Comment