zoukankan      html  css  js  c++  java
  • 使用ILookup<TKey, TElement> 接口查找集合

    public class Program
        {
            public static void Main()
            {
                // 创建一个放入ilookup数据结构的School清单。
                List<School> schools = new List<School> { new School { University = "西南交通大学",Address="成都"},
                                                     new School { University = "北京交通大学" ,Address="北京"},
                                                     new School { University = "西南政法大学" ,Address="重庆"},
                                                     new School { University = "北京航空航天大学" ,Address="北京"},
                                                     new School { University = "清华大学",Address="北京"} };
    
                // 创建一个查询来组织packages集合。使用大学的第一个字符作为关键值。
                //ILookup 对象中选择大学(University)附加大学地址(Address)作为每一个元素的值。
                ILookup<char, string> schoolLookup = schools.ToLookup(
                    p => Convert.ToChar(p.University.Substring(0, 1)),
                    p => p.University + " " +p.Address
                    );
    
                // 在ilookup遍历和输出内容的每个值。
                foreach (var packageGroup in schoolLookup)
                {
                    // 打印的关键值。
                    Console.WriteLine(packageGroup.Key);
                    // 遍历集合中的每个值。
                    foreach (string str in packageGroup)
                        Console.WriteLine("    {0}", str);
                }
            }
        }
        class School
        {
            public string University { get; set; }
            public string Address { get; set; }
        }
    

      

  • 相关阅读:
    sass和less的对比
    vue 源码分析
    vue的全家桶
    Vue组件化和路由
    开发技术文档汇总
    NodeJs前端构建工具 ——————之Grunt篇
    grunt使用小记之uglify:最全的uglify使用DEMO
    20 种提升网页速度的技巧
    webfont应用系列(二)如何制作图标字体?
    快速上手制作Icon Font
  • 原文地址:https://www.cnblogs.com/david1989/p/3333302.html
Copyright © 2011-2022 走看看