//以下省略using System等所有引用namespace A
{
    public class a
    {
        public void aa()
        {
            HttpContext.Current.Response.Write("aa");
        }
    }
}namespace B
{
    public class b : A.a
    {
        public void bb()
        {
            HttpContext.Current.Response.Write("bb");
        }
    }
}namespace C
{
    public class c : System.Web.UI.Page, B.b//出错
    {
        public void cc()
        {
            HttpContext.Current.Response.Write("cc");
        }
    }
}//Test.aspx.cs
public partial class Test : C.c
{
    protected void Page_Load(object sender, EventArgs e)
    {
        aa();
        bb();
        cc();
        Response.Write("Test");
    }
}我想最终在IE窗口输出"aabbccTest"简单点说就是想继承System.Web.UI.Page和B.b,然后直接使用,怎么写好?有人可能会说,用接口实现,那么,怎么实现最好?请大虾改一下这段代码让小弟明白,谢谢!!

解决方案 »

  1.   

    namespace A
    {
        public class a : System.Web.UI.Page
        {
            public void aa()
            {
                HttpContext.Current.Response.Write("aa");
            }
        }
    }namespace B
    {
        public class b : A.a
        {
            public void bb()
            {
                HttpContext.Current.Response.Write("bb");
            }
        }
    }namespace C
    {
        public class c : B.b
        {
            public void cc()
            {
                HttpContext.Current.Response.Write("cc");
            }
        }
    }//Test.aspx.cs
    public partial class Test : C.c
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            aa();
            bb();
            cc();
            Response.Write("Test");
        }
      

  2.   

    namespace A
    {
        public interface a
        {
            void aa();
        }
    }namespace B
    {
        public interface b : A.a
        {
            void bb();
        }
    }namespace C
    {
        public interface c : B.b
        {
            void cc();
        }
    }public partial class Test : System.Web.UI.Page, C.c
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            aa();
            bb();
            cc();
            Response.Write("Test");
        }
        public void aa()
        {
            HttpContext.Current.Response.Write("aa");
        }
        public void bb()
        {
            HttpContext.Current.Response.Write("bb");
        }
        public void cc()
        {
            HttpContext.Current.Response.Write("cc");
        }
    }
      

  3.   

    c#和java一样,没有多重继承的。只能继承一个父类,多个接口
      

  4.   

    using System;namespace A
    {    /// <summary>
        /// Summary description for Class1
        /// </summary>
        public partial class Test : System.Web.UI.Page
        {
            private List<RenderSomething> _renders;        public Test()
            {
            }        public Test(List<RenderSomething> renders)
            {
                _renders = renders;
            }        protected void Page_Load(object sender, EventArgs e)
            {
                if (_renders != null)
                {
                    foreach (RenderSomething item in _renders)
                    {
                        Response.Write(item.Render());
                    }
                }
            }
        }    public interface RenderSomething
        {
            String Render();
        }    public class A : RenderSomething
        {
            public String Render()
            {
                return "aa";
            }
        }    public class B : RenderSomething
        {
            public String Render()
            {
                return "bb";
            }
        }    public class C : RenderSomething
        {
            public String Render()
            {
                return "cc";
            }
        }
    }
      

  5.   

    错了, 初始化应该是:        public Test()
            {
                 _renders = new List<RenderSomethig>();
                 _render.add(new A());
                 _render.add(new B());
                 _render.add(new C());
            }
      

  6.   

    同志们,不是这样的
    对于这个问题最好首先搞清楚是要Is-A还是要Has-A
    如果要的是is-a则使用以上给出的正确的继承方式
    如果是has-a的话则是把某个合适的类的对象作为最终类的成员
      

  7.   

    /// <summary>
    /// Summary description for Class1
    /// </summary>
    namespace A
    {
        public class Test : System.Web.UI.Page
        {
            private IExample m_Example;
            public Test()
            {
                m_Example = new CExample();
            }        protected void Page_Load(object sender, EventArgs e)
            {
                Implement();
            }        private void Implement()
            {
                m_Example.FunExample_1();
                m_Example.FunExample_2();
                m_Example.FunExample_3();
            }
        }    interface IExample
        {
            string FunExample_1();
            string FunExample_2();
            string FunExample_3();
        }    class CExample : IExample
        {
            public CExample() { }        public string FunExample_1()
            {
                return "FunExample_1";
            }        public string FunExample_2()
            {
                return "FunExample_2";
            }        public string FunExample_3()
            {
                return "FunExample_3";
            }
        }}
      

  8.   

    对不起,条件没说清楚,补充一下:
    1.a、b不能有System.Web.UI.Page的方法
    2.Test不能实现方法,只能调用,并且只能继承c
    3.不能new对象,都要直接使用。(C++是可能的,如果c#可能的话)听说是可以实现多接口,那么我想到的是用c来继承System.Web.UI.Page,可是a和b的方法在c里面都要实现一次,好象很多余。听说可以用抽象类来解决,具体怎样?
      

  9.   

    namespace A 

        public class a 
        { 
            public void aa() 
            { 
                HttpContext.Current.Response.Write("aa"); 
            } 
        } 
    } namespace B : System.Web.UI.Page

        public class b : A.a 
        { 
            public void bb() 
            { 
                HttpContext.Current.Response.Write("bb"); 
            } 
        } 
    } namespace C 

        public class c : B.b
        { 
            public void cc() 
            { 
                HttpContext.Current.Response.Write("cc"); 
            } 
        } 
    } //Test.aspx.cs 
    public partial class Test : C.c 

        protected void Page_Load(object sender, EventArgs e) 
        { 
            aa(); 
            bb(); 
            cc(); 
            Response.Write("Test"); 
        } 

      

  10.   

    B.b继承System.Web.UI.Page,C.c继承B.b
      

  11.   


    namespace B : System.Web.UI.Page这一句可行吗?B.b继承System.Web.UI.Page,C.c继承B.ba呢?
      

  12.   

    改一下:
    namespace A
    {
        public interface a
        {
            void aa();
        }
    }namespace B
    {
        public interface b : A.a
        {
            void bb();
        }
    }namespace C
    {
        public class c : B.b
        {
               public void aa()
        {
            HttpContext.Current.Response.Write("aa");
        }
        public void bb()
        {
            HttpContext.Current.Response.Write("bb");
        }
        public void cc()
        {
            HttpContext.Current.Response.Write("cc");
        }
        }
    }public partial class Test : System.Web.UI.Page, C.c
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            aa();
            bb();
            cc();
            Response.Write("Test");
        }}
      

  13.   

    sorry,错了
    namespace A
    {
        public interface a
        {
            void aa();
        }
    }namespace B
    {
        public interface b : A.a
        {
            void bb();
        }
    }namespace C
    {
        public class c : System.Web.UI.Page, B.b
        {
            public void aa()
            {
                HttpContext.Current.Response.Write("aa");
            }
            public void bb()
            {
                HttpContext.Current.Response.Write("bb");
            }
            public void cc()
            {
                HttpContext.Current.Response.Write("cc");
            }
        }
    }public partial class Test : C.c
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            aa();
            bb();
            cc();
            Response.Write("Test");
        }
    }
      

  14.   

    10楼的namespace怎么能继承类呢???
      

  15.   

    跟我的原意不一样了,你把a和b两个类省去了,我还有很多类是继承了b类的,需要用到a和b里面的方法
    而又完全不需要c里的方法
      

  16.   

    就象前面说的,.NET不支持多重继承你的类,a,b 跟网页的东西有关么,为什么不在c类生成实例来使用呢?composition over inheritancenamespace A 

        public class a 
        { 
            public void aa() 
            { 
            } 
        } 
    } namespace B 

        public class b
        { 
            public void bb() 
            { 
            } 
        } 

    namespace C 

        public class c : System.Web.UI.Page
        { 
    A.a aaa = new A.a();
    B.b bbb = new B.b();        public void cc() 
            { 
        aaa.aa();
        bbb.bb();
                HttpContext.Current.Response.Write("cc"); 
            } 
        } 
    } 其实,如果是类库,最好别在其中调用HttpContext.Current,这样如果它们的功能很有用的话,在别的东西也可以重用它们
      

  17.   

    saucer好厉害,一下就看明白了我的用意,a,b确实是类库,还有很多类是继承它们的,都跟网页无关!
    a是我的基类,HttpContext.Current.Response.Write只是随便写的,实际上不会有之前大家所说的类继承接口,我觉得不叫"继承",而是"实现",因为"继承"的话,就象类继承类一样,父类的方法是不需重新实现(或者说不需要包装一下)
    接口继承接口,才是真正的"继承"..
    如果c#里无法完成象c++那样的真正意义上的多继承(即派生类不需要做任何事情,直接使用),我就会用saucer这方法小弟知识浅薄,如有说错的还请指点!谢谢大家ps:研究了几天,问过N多人,看来是没有再好的办法了,此贴还保留一天,明天结贴!