栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

查找的目的是什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

查找的目的是什么?

这是an

IGrouping
和字典之间的交叉。它使您可以通过键将项目分组在一起,然后以一种有效的方式通过该键访问它们(而不仅仅是遍历它们,这就是
GroupBy
您要做的事情)。

例如,您可以加载.NET类型并按名称空间构建查找…,然后非常轻松地获取特定名称空间中的所有类型:

using System;using System.Collections.Generic;using System.Linq;using System.Xml;public class Test{    static void Main()    {        // Just types covering some different assemblies        Type[] sampleTypes = new[] { typeof(List<>), typeof(string),     typeof(Enumerable), typeof(XmlReader) };        // All the types in those assemblies        IEnumerable<Type> allTypes = sampleTypes.Select(t => t.Assembly)   .SelectMany(a => a.GetTypes());        // Grouped by namespace, but indexable        ILookup<string, Type> lookup = allTypes.ToLookup(t => t.Namespace);        foreach (Type type in lookup["System"])        { Console.WriteLine("{0}: {1}",         type.FullName, type.Assembly.GetName().Name);        }    }}

(我通常会

var
在普通代码中使用大多数这些声明。)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506722.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号