首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

*C#有关base和this的初级有关问题

2012-03-07 
**********C#有关base和this的初级问题一段代码:usingSystemnamespaceMyNameSpace{publicclassPerson{pub

**********C#有关base和this的初级问题
一段代码:
using   System;
namespace   MyNameSpace
{
    public   class   Person
    {
        public   virtual   void   Print()
        {
            Console.WriteLine(base.ToString());
            Console.WriteLine(this.ToString());
        }
    }
    public   class   Student   :   Person
    {
        public   override   void   Print()
        {
            base.Print();
        }
    }
    public   class   MyClass
    {
        public   static   void   Main()
        {
            Person   p   =   new   Person();
            p.Print();
            Student   s   =   new   Student();
            s.Print();
            Console.ReadKey();
        }
    }
}
有关base和this两个不清楚,这个输出啥,为啥这样输出啊???请指教……

[解决办法]
base 指示 调用父类方法
this 表示 调用本类方法
[解决办法]
base 父类 相当于java中的super
this 本类指针

热点排行