我有一个twittercollection对象集合,保存在列表中。我通过foreach循环填充twittercollection对象(tc),然后通过linq访问它。
我的类及其属性如下:
//simple field definition class
public class TwitterCollection
{
public string origURL { get; set; }
public string txtDesc { get; set; }
public string imgURL { get; set; }
public string userName { get; set; }
public string createdAt { get; set; }
public string realURL { get; set; }
public string googleTitle { get; set; }
public string googleDesc { get; set; }
}
然后我继续用一个循环来填充它,循环遍历一组中的一组正则表达式匹配:
var list = new List<TwitterCollection>();
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
var tc = new TwitterCollection
{
origURL = groups[1].Value.ToString(),
txtDesc = res.text,
imgURL = res.profile_image_url,
userName = res.from_user_id,
createdAt = res.created_at,
};
list.Add(tc);
}
最后,我将使用LINQ查看该集合,并仅提取某些项进行显示:
var counts = from URL in list
group URL by URL into g
orderby g.Count()
select new { myLink = g.Key, Count = g.Count() };
所有这些的结果都是count.mylink中“twittercollection”一词的长列表,并且没有URL计数…
我以前把这些都处理好了,然后再把它们放到一个通用列表中。现在我搬来是为了方便,它不起作用了。
我真的很感激有人把我从这里的痛苦中解救出来!事先谢谢。