Dictionary --- dictionary <tkey, tvalue>

Source: Internet
Author: User
Tags id3

========================================================== ========= Employeeid. CS (student ID)

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication7 {// The type of the key must be rewritten gethashcode () public class employeeid: iequatable <employeeid> {Public String ID {Get; private set ;} public employeeid (string s) {id = s;} public override bool equals (Object OBJ) {If (OBJ = NULL) throw new argumentexception ("the object cannot be blank "); return this. equals (OBJ as employeeid);} public override int gethashcode () {return 1;} public bool equals (employeeid other) {return this. id = Other. id ;}}}

========================================================== ========== Student. CS (student)

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication7{    public class Student    {        public string Name { get; private set; }        public EmployeeID ID { get; private set; }        public Student(EmployeeID id, string name)        {            this.Name = name;            this.ID = id;        }    }}

========================================================== ========= Main program

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication7 {class program {static void main (string [] ARGs) {dictionary <employeeid, student> d = new dictionary <employeeid, student> (); vaR id1 = new employeeid ("z001"); var stu1 = new student (id1, "Zhang Fei"); D. add (id1, stu1); var Id2 = new employeeid ("z002"); var stu2 = ne W student (Id2, "Guan Yu"); D. add (Id2, stu2); var ID3 = new employeeid ("z003"); var stu3 = new student (ID3, "Cao"); D. add (ID3, stu3); var ID4 = new employeeid ("z004"); var stu4 = new student (ID4, "Zhao Yun"); D. add (ID4, stu4); var id5 = new employeeid ("z005"); var stu5 = new student (id5, "Ma Chao"); D. add (id5, stu5); While (true) {string STR = console. readline (); If (Str. tolower () = "exit") return; student s; EMP Loyeeid Ei = NULL; Ei = new employeeid (STR); If (! D. trygetvalue (EI, out S) // you can determine whether the corresponding key value exists. {console. writeline ("This student is not found");} else {console. writeline (d [ei]. name );}}}}}

650) This. width = 650; "style =" width: 742px; Height: 797px; "Title =" lexicographic .png "alt =" wkiom1qfx20.20.r1faajyt3ethqu611.jpg "src =" http://s3.51cto.com/wyfs02/M01/48/28/wKiom1QFxqfh7R1fAAJyT3EThQU611.jpg "width =" 669 "Height =" 793 "/>

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

Dictionary --- dictionary <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.