[C#]Base使用小记

base  关键字用于从派生类中访问基类的成员:
• 调用基类上已被其他方法重写的方法。
• 指定创建派生类实例时应调用的基类构造函数。
基类访问只能在构造函数、实例方法或实例属性访问器中进行。
从静态方法中使用 base 关键字是错误的。——MSDN
using System;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            WindowsPhone _wp = new WindowsPhone();
            _wp.Output();
            WindowPhone8 _wp8 = new WindowPhone8("8.1");
            _wp8.Output();
            Windowsphon7 _wpMango = new Windowsphon7("7.5 (Mango)");
            _wpMango.Output();
        }
    }
    public class WindowsPhone
    {
        protected string Brand = "Microsoft";
        protected string Model = "Surface Phone";
        public WindowsPhone()
        {
            Console.WriteLine("I'm Smart phone.");
            Console.WriteLine(string.Format("Brand:{0}", Brand));
            Console.WriteLine(string.Format("Model:{0}", Model));
        }
        public WindowsPhone(string name)
        {
            Console.WriteLine(string.Format("Windows Phone:{0}", name));
        }

        public virtual void Output()
        {
            Console.WriteLine("=======Remark======");
        }
    }
    public class Windowsphon7 : WindowsPhone
    {
        public Windowsphon7(string type)
            : base(type)
        {

        }
        public override void Output()
        {
            base.Output();
            Console.WriteLine("On September 27, 2011, Microsoft has officially released Windows Phone7.5 Smartphone operating system, were WindowsPhone 7 research and development on the basis of the new version, make up for the shortcomings of many of its and running speed has increased significantly.");
        }
    }
    public class WindowPhone8 : WindowsPhone
    {
        WindowPhone8()
            : base()
        {
        }
        public WindowPhone8(string type)
            : base(type)
        {

        }
        public override void Output()
        {
            base.Output();
            Console.WriteLine("Intelligent systems for window phone 8.1 is Microsoft's latest mobile phone.");
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

代码效果

[C#]Base使用小记

上一篇:paip.关于动画特效原理 html js 框架总结


下一篇:多核优化