我有一个有这个代码的类,
pCollection pub = RSSXmlDeserializer.GetPub(path, fReload);
get pub 是返回 pub 集合的方法...
我怎样才能迭代它们。我试过,
for (var n = 0; n < pub.Count; n++ ){
}
这是 getPub 方法
public static PCollection GetPub(string path, bool fReload)
{
HttpApplicationState session = HttpContext.Current.Application;
PCollection pub = session["PUB"] as PCollection;
if pub == null || fReload)
{
StreamReader reader = null;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(PCollection));
reader = new StreamReader(path);
pub = (PCollection)serializer.Deserialize(reader);
session["PUB"] = pub;
}
catch (Exception ex)
{
//throw ex;
}
finally
{
reader.Close();
}
}
return pub;
}
}
[Serializable()]
public class Pub
{
[System.Xml.Serialization.XmlElement("title")]
public string Title { get; set; }
[System.Xml.Serialization.XmlElement("description")]
public string Description { get; set; }
[System.Xml.Serialization.XmlElement("imageUrl")]
public string ImageUrl { get; set; }
}
[Serializable()]
[System.Xml.Serialization.XmlRoot("RPublications")]
public class PCollection
{
[XmlArray("Pub")]
[XmlArrayItem("Pub", typeof(Pub))]
public Pub[] Pub { get; set; }
}
但“计数”不被识别。我收到此消息,pCollection 没有“计数”的定义...
我如何迭代集合 n 获取集合元素?请帮忙。