首页 > Web开发 > 详细

.NET 之 List

时间:2016-06-17 08:30:12      阅读:294      评论:0      收藏:0      [点我收藏+]

有三个类,请思考:

用相对较优的做法来找到所有帖子的Tag和Reply:

class Post
{
    public int ID { get; set; }
    public int TagId { get; set; }
    public int ReplyId { get; set; }
}
class Tag
{
    public int ID { get; set; }
    public string Name { get; set; }
}
class Reply
{
    public int ID { get; set; }
    public string Name { get; set; }
}

为了方便描述,那么就给定三个List<T>:

List<Post> postList = new List<Post>();
List<Tag> tagList = new List<Tag>();
List<Reply> replyList = new List<Reply>();

思路:

1:分别便利tagList和replyList并转换为Dictionary

2:便利postList,并根据Id来获取对应的信息

原理:

充份利用了索引的概念(Dictionary为KeyValuePars的List)

本文出自 “lybing” 博客,请务必保留此出处http://lybing.blog.51cto.com/3286625/1790134

.NET 之 List

原文:http://lybing.blog.51cto.com/3286625/1790134

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!