zoukankan      html  css  js  c++  java
  • 对Dictionary操作 查找项和排序 [代码记录]

    KeyCollection:
      
    protected void Page_Load(object sender, EventArgs e)
            
    {
                
    if (!IsPostBack)
                
    {
                   EmployeeCollection employees 
    =
                   
    new EmployeeCollection();
                    employees.Add(
    new Employee(1"Joe"));
                    employees.Add(
    new Employee(2"Jim"));
                    employees.Add(
    new Employee(3"Jane"));
                    
    if (employees.Contains(3))
                    
    {
                        Employee emp 
    = employees[3];
                        Console.WriteLine(
                            
    "Employee ID={0}, Name={1}",
                            emp.ID, emp.Name);
                    }

                    Console.ReadLine();
                }

            }

    internal class Employee
            
    {
                
    public readonly int ID;
                
    public string Name;

                
    public Employee(int id, string name)
                
    {
                    
    this.ID = id;
                    
    this.Name = name;
                }

            }


            
    internal class EmployeeCollection : KeyedCollection<Int32, Employee>
            
    {
                
    protected override int GetKeyForItem(Employee item)
                
    {
                    
    return item.ID;
                }

            }
     1GroupDictionary:
     2     internal class GroupDictionary<T> : Dictionary<String, List<T>>
     3        {
     4            public void Add(String key, T value)
     5            {
     6                List<T> list = null;
     7                if (!this.ContainsKey(key) || !(this.TryGetValue(key, out list)))
     8                {
     9                    list = new List<T>();
    10                    this.Add(key, list);
    11                }

    12                list.Add(value);
    13            }

    14        }
  • 相关阅读:
    修改linux的hostname (修改linux系统的IP和hostname)
    linux自动ftp上传与下载文件的简单脚本
    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)
    用SQL命令查看Mysql数据库大小
    linux screen 命令详解
    mysql常用命令
    Linux 设置mysql开机启动
    源码编译mysql 5.5+ 安装过程全记录
    nagios-plugins安装报错--with-mysql: no
    Spark 中在处理大批量数据排序问题时,如何避免OOM
  • 原文地址:https://www.cnblogs.com/RuiLei/p/1077878.html
Copyright © 2011-2022 走看看