C# 简单工厂

如下:

public static IList<T> Create<T>(Type type)
{
    if (type == typeof(List<T>))
    {
        return new List<T>();
    }
    if (type == typeof(T[]))
    {
        return new T[0];
    }
    throw new Exception();
}

 

posted on 2013-08-04 19:41  yao2yao4  阅读(91)  评论(0编辑  收藏  举报

导航