C#通过显示接口实现解决命名冲突

来源:互联网 发布:华为怎么卸载软件 编辑:程序博客网 时间:2024/06/02 09:23

public interface IDrawToFrom
    {
        void Draw();
    }

    public interface IDrawToMemory
    {
        void Draw();
    }

    public interface IDrawPrinter
    {
        void Draw();
    }

    public class Octagon : IDrawToFrom, IDrawToMemory, IDrawPrinter
    {
        void IDrawToFrom.Draw()
        {
            System.Console.WriteLine("drawing to form...");
        }

        void IDrawToMemory.Draw()
        {
            System.Console.WriteLine("drawing to memory...");
        }

        void IDrawPrinter.Draw()
        {
            System.Console.WriteLine("drawing to printer...");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //通过显示接口实现解决命名冲突
            Octagon oct = new Octagon();

            ((IDrawToFrom)oct).Draw();

            ((IDrawToMemory)oct).Draw();

            ((IDrawPrinter)oct).Draw();

        }
    }

0 0
原创粉丝点击