zoukankan      html  css  js  c++  java
  • LinQ转换运算符ToDictionary

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ToDictionaryDemo
    {
        class Program
        {
            public class Game
            {
                public string Opponent { get; set; }
                public string Score { get; set; }
            }
            static void Main(string[] args)
            {
                var spartans = new List<Game>
                {
                    new Game{Opponent="UAB",Score="55-18"},
                    new Game{Opponent="Bowling Green",Score="55-18"},
                    new Game{Opponent="Pittsburgh",Score="55-18"},
                    new Game{Opponent="Notre Dame",Score="55-18"}
                };
                //字典是一种键值对的集合,ToDictionary 将一个IEnumerable<T>对象(比如LINQ查询所返回的结果)
                //转换为一个IDictionary<Key,Value>对象。
                IDictionary<string, Game> stats = spartans.ToDictionary(key => key.Opponent);
                Console.WriteLine("Spartans vs. {0} {1}", stats["Notre Dame"].Opponent, stats["Notre Dame"].Score);
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    Python从文件中读取数据
    Python中类的继承
    Python中的类(2)
    Python中的类
    自动登陆抽屉(1)
    爬取汽车之家新闻
    Django简介
    web应用,http协议简介,web框架
    CentOS7安装python3.6
    MySQL之索引
  • 原文地址:https://www.cnblogs.com/swtool/p/3840167.html
Copyright © 2011-2022 走看看