0

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

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

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

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

}
4

1 回答 1

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>();
于 2013-10-17T12:37:44.167 回答