码迷,mamicode.com
首页 > 其他好文 > 详细

仓储抽象类演示

时间:2015-06-04 22:27:52      阅读:122      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!