从收到的对象创建列表?

时间:2013-10-17 12:34:09

标签: c#

我需要从我的班级收到的对象创建一个列表。但我不能这样做?

[XmlTypeAttribute(AnonymousType = true)]
public class PackIt
{

    [XmlElement("pack")]
    public List<object> objects { get; set; }

    public PackIt(object model)
    {
         objects = new List<model.GetType()>();
    }

}

1 个答案:

答案 0 :(得分:0)

您可以PackIt通用:

[XmlTypeAttribute(AnonymousType = true)]
public class PackIt<T>
{

    [XmlElement("pack")]
    public List<T> objects { get; set; }

    public PackIt()
    {
         objects = new List<T>();
    }

}

PachIt<string> packIt = new PackIt<string>();