using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication106
{
    class Program
    {
        public interface Other
        {
            void Action();
        }
        public interface Sponsor
        {
            void RestWith(Other oth);
        }
        public class Mouse : Other
        {
            private string name;
            public Mouse(string name, Sponsor spo)
            {
                this.name = name;
                spo.RestWith(this);
            }
            public void Action()
            {
                Console.WriteLine(name + "escaped!");
            }
        }
        public class Master : Other
        {
            public Master(Sponsor spo)
            {
                spo.RestWith(this);
            }
        }
        public void Action()
        {
            Console.WriteLine("master was awakened!");
        }
        public class Cat : Sponsor
        {
            private ArrayList others;
            public Cat()
            {
                this.others = new ArrayList();
            }
            public void RestWith(Other oth)
            {
                this.others.Add(oth);
            }
            public void Yell()
            {
                Console.WriteLine("Cat yelling!");
                foreach (Other oth in this.others)
                {
                    oth.Action();
                }
            }
        }        class MainClass
        {
            static void Main(string[] args)
            {
                Cat cat = new Cat();
                Mouse mouse1 = new Mouse(mouse1, cat);
                Mouse mouse2 = new Mouse(mouse2, cat);
                Master master = new Master(cat);
                cat.Yell();
            }
        }
    }
}
错误提示是:Error 1'ConsoleApplication106.Program.Master' 未實作介面成員 'ConsoleApplication106.Program.Other.Action()'

解决方案 »

  1.   

    这不很明显, Master没实现Action()方法。
      

  2.   

    各位帮运行一下 我把Master的Action方法弄到Master括号里面了 然后出现了更多的错误
      

  3.   


    现在实现了 下面Mouse mouse1 = new Mouse(mouse1, cat);
      Mouse mouse2 = new Mouse(mouse2, cat);这里提示错误 :最符合的多载方法···有一些无效的引数 引數 '1': 無法從 'ConsoleApplication106.Program.Mouse' 轉換為 'string'
    mouse2也是这个错误 
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;namespace ConsoleApplication106
    {
        class Program
        {
            public interface Other
            {
                void Action();
            }
            public interface Sponsor
            {
                void RestWith(Other oth);
            }
            public class Mouse : Other
            {
                private string name;
                public Mouse(string name, Sponsor spo)
                {
                    this.name = name;
                    spo.RestWith(this);
                }
                public void Action()
                {
                    Console.WriteLine(name + "escaped!");
                }
            }
            public class Master : Other
            {
                public Master(Sponsor spo)
                {
                    spo.RestWith(this);
                }
                public void Action()
                {
                    Console.WriteLine("master was awakened!");
                }
            }
            public class Cat : Sponsor
            {
                private ArrayList others;
                public Cat()
                {
                    this.others = new ArrayList();
                }
                public void RestWith(Other oth)
                {
                    this.others.Add(oth);
                }
                public void Yell()
                {
                    Console.WriteLine("Cat yelling!");
                    foreach (Other oth in this.others)
                    {
                        oth.Action();
                    }
                }
            }        class MainClass
            {
                static void Main(string[] args)
                {
                    Cat cat = new Cat();
                    Mouse mouse1 = new Mouse(mouse1, cat);
                    Mouse mouse2 = new Mouse(mouse2, cat);
                    Master master = new Master(cat);
                    cat.Yell();
                }
            }
        }
    }
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;namespace ConsoleApplication106
    {
        class Program
        {
            public interface Other
            {
                void Action();
            }
            public interface Sponsor
            {
                void RestWith(Other oth);
            }
            public class Mouse : Other
            {
                private string name;
                public Mouse(string name, Sponsor spo)
                {
                    this.name = name;
                    spo.RestWith(this);
                }
                public void Action()
                {
                    Console.WriteLine(name + "escaped!");
                }
            }
            public class Master : Other
            {
                public Master(Sponsor spo)
                {
                    spo.RestWith(this);
                }
                public void Action()
                {
                    Console.WriteLine("master was awakened!");
                }
            }
            public class Cat : Sponsor
            {
                private ArrayList others;
                public Cat()
                {
                    this.others = new ArrayList();
                }
                public void RestWith(Other oth)
                {
                    this.others.Add(oth);
                }
                public void Yell()
                {
                    Console.WriteLine("Cat yelling!");
                    foreach (Other oth in this.others)
                    {
                        oth.Action();
                    }
                }
            }        class MainClass
            {
                static void Main(string[] args)
                {
                    Cat cat = new Cat();
                    Mouse mouse1 = new Mouse(mouse1, cat);
                    Mouse mouse2 = new Mouse(mouse2, cat);
                    Master master = new Master(cat);
                    cat.Yell();
                }
            }
        }
    }
      

  6.   

    ......低级错误......
    1)class MainClass
            {
                static void Main(string[] args)
                {
                    Cat cat = new Cat();
                    string mouse1 = "mouse1";
                    string mouse2 = "mouse2";
                    Mouse _mouse1 = new Mouse(mouse1, cat);
                    Mouse _mouse2 = new Mouse(mouse2, cat);
                    Master master = new Master(cat);
                    cat.Yell();
                }
            }//原因自己想2)public void Yell()
                {
                    Console.WriteLine("Cat yelling!");
                    foreach (Other oth in this.others)
                    {
                        oth.Action();
                    }
                    Console.ReadLine();//加这句,要不你看不到结果
                }
      

  7.   

    哟 确实是这样 不过 下面第二条建议 用ctrl+F5就中  谢谢了  确实是低级错误  没办法 虽然我学了快4个月了 但是都是自己在看书 公司都没人管我···