| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 710 人关注过本帖
标题:关于c#工厂模式
取消只看楼主 加入收藏
rgbtdkjcel
Rank: 1
等 级:新手上路
帖 子:294
专家分:0
注 册:2007-3-26
结帖率:50%
收藏
 问题点数:0 回复次数:0 
关于c#工厂模式
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    public class one
    {
        public virtual void print()
        { }
    }
    public class two : one
    {
        public override void print()
        {
            Console.Write("two方法");
        }
    }
    public class three : one
    {
        public override void print()
        {
            Console.Write("three方法");
        }
    }
    public class im
    {
        public static one returnclass(string name)
        {
            switch (name)
            {
                case "two":
                    return new two();
                case "three":
                    return new three();
            }
           // return null;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            one adm = im.returnclass("three");
            adm.print();
        }
    }
}


请问一下。。c#中的工厂模式是不是一定要使用抽象类来定义呢?还有。在returnclass函数中。为何将return null注释后,提示错误呢?为何不能注释掉呢?
搜索更多相关主题的帖子: 模式 工厂 
2009-10-13 10:36
快速回复:关于c#工厂模式
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055413 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved