Dictionary --- ordered Dictionary (sorteddictionary <tkey, tvalue>)

Source: Internet
Author: User

---------------------------------------------------------------- Employeeid. CS (key)

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections;public class EmployeeID : IComparable<EmployeeID>{    public int ID { get; private set; }    public EmployeeID(int id)    {        this.ID = id;    }       public int CompareTo(EmployeeID other)    {        return ID.CompareTo(other.ID);    }}

---------------------------------------------------------------- Person. CS

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{    public class Person    {        public string Country { get; private set; }        public string Name { get; private set; }        public int Age { get; private set; }        public Person(string country, string name, int age)        {            this.Country = country;            this.Name = name;            this.Age = age;        }           }}

-------------------------------------------------------------- Main program

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication1 {class program {static void main (string [] ARGs) {// sortedlist <tkey, tvalue> uses less memory // sorteddictionary <tkey, tvalue> fast element insertion and deletion // The key must implement the icomparable <in T> interface sorteddictionary <employeeid, person> SD = new sorteddictionary <employeeid, person> (); SD. add (New employeeid (3), new person ("China", "Zhang Fei", 40); SD. add (New employeeid (20), new person ("China", "Guan Yu", 43); SD. add (New employeeid (4), new person ("China", "Liu Bei", 45); SD. add (New employeeid (5), new person ("China", "Zhuge Liang", 24); SD. add (New employeeid (1), new person ("USA", "clerk", 40); SD. add (New employeeid (0), new person ("USA", "Obama", 40); SD. add (New employeeid (210), new person ("North Korea", "Jin San fat", 40); SD. add (New employeeid (80), new person ("India", "India a 3", 40); foreach (VAR item in SD) {console. writeline (item. key. ID + "," + item. value. name); // key, positive order} console. readkey ();}}}

 

This article from the "programmer's home" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1548070

Dictionary --- ordered Dictionary (sorteddictionary <tkey, tvalue>)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.