日期:2014-05-16  浏览次数:20785 次

关于一个非常简单的c#构造函数的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example135
{

    public class Note 
    {
        public Note(string s)
        {
            Console.WriteLine("Creating Note with: {0}", s);
        }

    }
    public class Document : Note
    {
        public  Document(string s) : base(s)
        {
            Console.WriteLine("Creating Document with: {0}", s);
        }

    }
    class Tester
        {
        static void Main( )
        {
            Note n1 = new Note("note");
            Note n2 = new Document("document");
        }
    }
}


如何不让红线处的这句话显示出来,其本质就直接构造document的时候不出现父类构造函数?谢谢



------解决方案--------------------
呵呵,不构建父类怎么能构建出子类。
没有爹哪来的孩子,私生子也是有父母的!!!
------解决方案--------------------
如果用继承,一定会有的,除非把继承关系转换成包含关系

------解决方案--------------------
引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example135
{

    public class Note 
    {
        public Note(string s)
        {
            Console.WriteLine("Creating Note with: {0}", s);
        }

    }
    public class Document : Note
    {
        public  Document(string s) : base(s)
        {
            Console.WriteLine("Creating Document with: {0}", s);
        }

    }
    class Tester
        {
        static void Main( )
        {
            Note n1 = new Note("note");
            Note n2&