深入理解 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

猜你喜欢

转载自blog.csdn.net/eyetired/article/details/80248708