惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cybersecurity and Infrastructure Security Agency CISA
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Schneier on Security
L
Lohrmann on Cybersecurity
S
Securelist
P
Palo Alto Networks Blog
SecWiki News
SecWiki News
T
Troy Hunt's Blog
H
Hacker News: Front Page
AWS News Blog
AWS News Blog
Latest news
Latest news
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
The Hacker News
The Hacker News
F
Full Disclosure
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
O
OpenAI News
P
Proofpoint News Feed
Know Your Adversary
Know Your Adversary
G
GRAHAM CLULEY
博客园_首页
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题
博客园 - 叶小钗
L
LINUX DO - 最新话题
Martin Fowler
Martin Fowler
N
News | PayPal Newsroom
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
PCI Perspectives
PCI Perspectives
月光博客
月光博客
IT之家
IT之家
Recent Announcements
Recent Announcements
T
The Exploit Database - CXSecurity.com
D
DataBreaches.Net
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - Snapping

PLSQL-Developer beautifier xml skill note Delete temp files to get more disk space 设置控件text(兼容浏览器) Oracle: where to add tns key sql server process query Default permissions and user rights for IIS 6.0 C#获取项目程序路径的方法 Get the source code via a url __doPostBack ASP.NET 2.0 中的UrlRewrite var container = $get('divA'); var links = container.getElementsByTagName("A"); static variables and web.config file Register dll for asp application The report server cannot decrypt the symmetric key install report server 短歌行 CSS: 在半透明的层上放一个不透明层 技巧和诀窍;在VS 2005里优化ASP.NET 2.0Web项目的Build性能
泛型 List 和 Dictionary 类的互相转换
Snapping · 2008-01-11 · via 博客园 - Snapping

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace testcs
{
    
class Program
    {
        
static void Main(string[] args)
        {
            ListAndDictionary();

        }

/// <summary>
        
/// 泛型 List 和 Dictionary 类的互相转换
        
/// </summary>
        private static void ListAndDictionary()
        {
            
// dict -> list 
            
// 转换为 List<T>,T 的类型是 KeyValuePair<TKey, TValue>
            Dictionary<stringint> d = new Dictionary<stringint>();
            var l 
= d.ToList();

            List

<KeyValuePair<stringint>> l2 = new List<KeyValuePair<stringint>>{
                
new KeyValuePair<string,int>("a"1),
                
new KeyValuePair<string,int>("b"2)
            };
// list -> dict 两种转换方式// 1. 可指定 keySelector 和 valueSelector;完全自定义字典 key, value 的类型            
            Dictionary<stringint> d2 = l2.ToDictionary(entry => entry.Key, entry => entry.Value);
            
// 2. 也可只指定 keySelector, value 为 entry 的值。
            Dictionary<float, KeyValuePair<stringint>> d3 = l2.ToDictionary(
                entry 
=> (float)entry.Value);
        }
    }
}