• Dictionary<string, Dictionary<string, Person>> dic = new Dictionary<string, Dictionary<string, Person>>();


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication4
    {
    class Program
    {
    static void Main(string[] args)
    {
    Dictionary<string, Dictionary<string, Person>> dicFull = Person.GetFullDic();

    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    sw.Start();
    Dictionary<string, Person> dicPerson = dicFull["South"];
    Person person = dicPerson["15"];
    Console.WriteLine(person.Province + "," + person.Id + "," + person.Name + "," + person.Age);
    sw.Stop();
    Console.WriteLine("Cost " + sw.ElapsedMilliseconds.ToString()+" milliseconds");
    Console.ReadLine();
    }


    }

    public class Person
    {
    public string Province { get; set; }
    public string Id { get; set; }

    public string Name { get; set; }

    public string Age { get; set; }

    public static Dictionary<string,Person> GetDic()
    {
    Dictionary<string, Person> dicPerson = new Dictionary<string, Person>();
    for(int i=0;i<10;i++)
    {
    var key = i.ToString();
    Person value = new Person()
    {
    Province = "SH",
    Id = i.ToString(),
    Name = "Fred" + i,
    Age = "Age" + i
    };
    dicPerson.Add(key, value);
    }

    for(int i=10;i<20;i++)
    {
    var key = i.ToString();
    Person value = new Person()
    {
    Province = "JS",
    Id = i.ToString(),
    Name = "WYQ" + i,
    Age = "Age" + i
    };

    dicPerson.Add(key, value);
    }

    return dicPerson;
    }

    public static Dictionary<string,Dictionary<string,Person>> GetFullDic()
    {
    Dictionary<string, Dictionary<string, Person>> dic = new Dictionary<string, Dictionary<string, Person>>();
    Dictionary<string, Person> dicPerson = Person.GetDic();
    var key1 = "North";
    dic.Add(key1, dicPerson);
    var key2 = "South";
    dic.Add(key2, dicPerson);

    return dic;
    }
    }
    }

  • 相关阅读:
    windows向Linux服务器上传、下载,服务器内复制、移动文件
    解决:ubuntu提示E: 无法获得锁 /var/lib/dpkg/lock-frontend
    PostgreSQL安装与简单操作
    LeetCode 234.回文链表
    LeetCode 445.两数相加 II
    LeetCode 24.两两交换链表中的节点
    LeetCode 19.删除链表的倒数第 n 个节点
    LeetCode 26.删除排序数组中的重复项
    Java 程序运行机制
    String 属于基础的数据类型吗?
  • 原文地址:https://www.cnblogs.com/Fred1987/p/6111366.html
Copyright © 2020-2023  润新知