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        }
  • 相关阅读:
    RECOVER DATABASE SKIP TABLESPACE
    mysql加解密函数
    node获取代码的svn版本号,并打包的时候,输出指定文件到打包后的项目里面
    layer.open iframe自动高度
    IIS部署.net5项目
    使用Windows命令行启动关闭服务(net,sc用法)(转)
    centos7 修改IP 设置静态IP,开启SSH
    链接PostgreSQL报错authentication method 10 not supported解决
    PostgreSQL Windows安装教程
    POI隐藏行 隐藏列,EasyExcel隐藏行 EasyExcel隐藏列
  • 原文地址:https://www.cnblogs.com/RuiLei/p/1077878.html
Copyright © 2011-2022 走看看