How to Use hashtable [hash table] of C #

Source: Internet
Author: User
Tags visual studio 2010

In C # programming, you often need to process some key-value pairs. Generally, you can use dictionaries or hash tables. Compared with dictionaries, hash tables consume less system resources.

The following is an example of common hash table methods:

1. Add elements;

2. delete an element;

3. traversal;

4. query.

Step-by-Step reading tools/Raw Materials
  • Microsoft Visual maxcompute 2010

Method/step
  1. 1

    Open Microsoft Visual Studio 2010 and create a program named [hash table.

  2. 2

    Place appropriate controls in the blank window of the new program interface: including,

    Displays the Textbox Control of the operation flow;

    Add four button controls, click Add, view, clear, and query ];

    Two textbox controls for adding data to a user: Name and mobile phone number ];

    Enter two textbox controls for data query.

    Steps
  3. 3

    Add a new hash table in the code.

    Edit the Add button code to obtain user input data and add it to the hash table.

    Step 1
  4. 4

    Edit the [view] button code

    Traverse the hash table and output each element.

    Steps
  5. 5

    Edit the Clear button code

    Clear the hash table.

    Steps
  6. 6

    Edit the query button code

    If you select a name query, the system checks whether the key of the hash table matches;

    If you select a telephone query, you can determine whether the hash table value matches;

    Steps
  7. 7

    Generate an EXE file for testing,

    Add data for three employees respectively.

    Steps
  8. 8

    Click View to view information about the three employees.

    Steps
  9. 9

    Select "by name", enter a name that does not exist, and click "query". "No corresponding data" is displayed ].

    Steps
  10. 10

    Enter an existing name and click query to display [corresponding data ].

    Steps
  11. 11

    Select "by phone", enter a phone number that does not exist, and click "query" to display "no data ].

    Steps
  12. 12

    Enter an existing phone number and click query. The corresponding data is displayed ].

    Steps
  13. 13

    Click Clear to clear all hash table data. Click View. No hash table data is output, indicating that the hash table has no data.

    Step: Read end

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.