public class Content : Form, Observer
{
  public Content()
  {
    MessageBox.Show(this.Name);//在这里我希望输出的是实例的Name,也就是:FIN020201Form,现在实际输出的是Content
  }
}
public partial class FIN020201Form : Content
{
  public FIN020201Form()
  {  }
}

解决方案 »

  1.   

    nForm   nf=new   nForm   ();
    MessageBox.Show(nf.Name)
      

  2.   


    public class Content : Form, Observer
        {
            public Content()
            {
                MessageBox.Show(GetFormName());//在这里我希望输出的是实例的Name,也就是:FIN020201Form,现在实际输出的是Content 
            }        protected virtual string GetFormName()
            {
                return this.Name;
            }
        }
        public partial class FIN020201Form : Content
        {
            public FIN020201Form()
            {        }        protected override string GetFormName()
            {
                return this.Name;
            }
        } 可以这样试试看
      

  3.   

    谢谢大家,3楼typeof(FIN020201Form).Name,FIN020201Form不确定啊,如果确定就不用这么麻烦了。
    4楼不明白啥意思。
    5楼我试了,输出还是Content,麻烦大家继续关注。
      

  4.   

    public class Content : Form, Observer
        {
            public Content()
            {
                MessageBox.Show(GetFormName());//在这里我希望输出的是实例的Name,也就是:FIN020201Form,现在实际输出的是Content 
            }        protected virtual string GetFormName()
            {
                return this.Name;
            }
        }
        public partial class FIN020201Form : Content
        {
            public FIN020201Form()
            {        }        protected override string ClassName()
            {
                return "FIN020201Form";
            }
        } 这个可以"ClassName" 可以写在父类里,用虚方法
    在每个继承的类里实现就可以了!
      

  5.   

    测试代码:
    Content c = new FIN020201Form();public class Content : Form, Observer
        { 
            public Content()
            {
                MessageBox.Show(this.Name);//在这里我希望输出的是实例的Name,也就是:FIN020201Form,现在实际输出的是Content 
            }        protected string GetName()
            {
                return this.GetType().Name;
            }        public new string Name 
            {
                get 
                {
                    return GetName();
                }
                set 
                {
                    base.Name = value;
                }
            }
        }
        public partial class FIN020201Form : Content
        {
            public FIN020201Form()
            {        }
        } 
      

  6.   

            protected string GetName()
            {
                return this.GetType().Name;
            }
            这个只是是获得Type的Name        你可以定义其为虚函数,在FIN020201Form 重写这个函数获取你要名称
      

  7.   

     Content.cs
    public virtual string ClassName
            {
                get;
            }
    FIN020201Form.csprotected override string ClassName() 
            { 
                return "FIN020201Form"; 
            } 
      

  8.   


    谢谢,使用this.GetType().Name可以。
    问题解决。
      

  9.   


    namespace WindowsApplication15
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                FIN020201Form f = new FIN020201Form();
            }        public interface IGetName
            {
                String GetName();
            }        public class Content : Form,IGetName
            {
                public String GetName()
                {
                    return this.GetType().ToString();
                }
            
                public Content()
                {
                    MessageBox.Show(GetName());//在这里我希望输出的是实例的Name,也就是:FIN020201Form,现在实际输出的是Content 
                }
            }
            public partial class FIN020201Form : Content
            {
                public String GetName()
                {
                    return this.GetType().Name.ToString();
                }
            } 
        }
    }
      

  10.   

    ....e,对了,我怎么给忘了,其实gettype已经会自动判断了,也就不用接口、虚函数、继承之类的麻烦事了
      

  11.   

    this.Name 的值本身就是在构造函数中赋的
      

  12.   

    基类构造中有
    this.Name = “Content”;
    MessageBox.Show(this.Name);子类中有
    this.Name = “FIN020201Form“
    当new FIN020201Form()时
    先构造基类再子类,当然会是Content