深入理解 c# 第十一章 使用group...by进行分组 通过分配者分组 投影只保留摘要

    class GroupDefectsByAssigneeWithProjection
    {
        static void Main()//通过分配者分组  投影只保留摘要 使用group...by进行分组
        {
            var query = from defect in SampleData.AllDefects
                        where defect.AssignedTo != null
//有41个defect 只写第一个 还有40个defect
//{ 1: MP3 files crash system    (2013/5/1-2013/5/23, Showstopper/Accepted, Tim Trotter -> Darren Dahlia)}
						
                        group defect.Summary by defect.AssignedTo;
//query {System.Linq.GroupedEnumerable<Chapter11.Model.Defect,Chapter11.Model.User,string>}

            foreach (var entry in query)
//entry {System.Linq.Lookup<Chapter11.Model.User,string>.Grouping}
			
            {
                Console.WriteLine(entry.Key.Name);
                foreach (var summary in entry)
				//summary "MP3 files crash system"
				//"Can't play files more than 200 bytes long"
				//"DivX is choppy on Pentium 100" 等等 按summary 首字母排序
                {
                    Console.WriteLine("  {0}", summary);
                }
                Console.WriteLine();
            }
        }
    }


 投影的是缺陷的概要,每个条目中内嵌的序列为IEnumerable<string>。在这个例子,编译器
使用GroupBy的一个重载版本,它用另一个参数来表示投影。
  分组句子虽然相对简单,却相当有用。即使在我们缺陷跟踪系统中,除了使用的分配者外,还

可以使用项目,创建者,严重程度或状态来进行分组。


输出
Darren Dahlia
  MP3 files crash system
  Can't play files more than 200 bytes long
  DivX is choppy on Pentium 100
  User interface should be more caramelly
  Peer to peer pairing passes parameters poorly
  Volume control needs to go to 11
  Subtitles don't display during fast forward
  Unable to connect to any media server
  Modern music sounds rubbish
  Sound is distorted when speakers are underwater
  DVD Easter eggs unavailable
  Logs record confidential conversations
  Resizing while typing loses input
  Media library tells user to keep the noise down


Tara Tutu
  Sky is wrong shade of blue
  Delay when sending message
  Splash screen fades too quickly
  UI turns black and white when playing old films
  Profanity filter is too aggressive


Tim Trotter
  Installation is slow
  Subtitles only work in Welsh
  Play button points the wrong way
  Webcam makes me look bald
  Network is saturated when playing WAV file


Deborah Denton
  Text box doesn't keep up with fast typing
  Memory leak when watching Memento
  Profile screen shows login count of -1
  Server crashes under heavy load (3 users)
  Japanese characters don't display properly
  Video takes 100% of CPU
  Transparency is high for menus to be readable
  Full screen mode fails on dual monitors
  Visualization hypnotises pets


Colin Carton
  Wizard needed for CD burning
  About box is missing version number

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值