首页 > 其他 > 详细

仓储抽象类演示

时间:2015-06-04 22:27:10      阅读:189      评论:0      收藏:0      [点我收藏+]
技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("你要什么电脑?");
            string strs = Console.ReadLine();
             Brand _bran =  Faloy.GetBranName(strs);
             _bran.ShowBrand();

        }



    }


    public abstract class Brand
    {
        public abstract void ShowBrand();
    }

    public class Dell : Brand
    {

        public override void ShowBrand()
        {
            Console.WriteLine("Dell");
        }
    }
    public class HP : Brand
    {
        public override void ShowBrand()
        {
            Console.WriteLine("HP");
        }
    }


    public static class Faloy
    {
        public static Brand GetBranName(string str)
        {
            if (str == "dell")
                return new Dell();
            else if (str == "hp") return new HP();
            return null;
        }
    }
}
View Code

 

仓储抽象类演示

原文:http://www.cnblogs.com/KevinDai/p/4553137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!