Lan Unity Development Fundamentals Two--lesson 24 Dictionary

Source: Internet
Author: User

Lan Unity Development Fundamentals Two--lesson 24 Dictionary

one, Dictionary

Dictionary is a collection of stored keys and values

Dictionary are unordered, key keys are unique

Recommended Video lecturer Blog: http://11165165.blog.51cto.com/


usingSystem;
// Reference generic collection namespace
usingSystem.Collections.Generic;

namespacelesson_24
{
    class MainClass
    {
         public Static voidMain (string[] Args)
        {
            // Create a dictionary object, The type of key is string, The type of Value is int
            Dictionary<string,int> Dic=New Dictionary<string,int> ();

             The//add method is used to add a Key-value pair
Dic. ADD ("laowang", -);
Dic. ADD ("laozhang", -);

            // Remove key-value pairs from the dictionary
Dic. Remove ("laowang");

            // Empty current dictionary
Dic. Clear ();

            //gets The number of KeyValue in the current dictionary
            intcount = Dic. Count;
            Console. WriteLine (" There are in the current dictionary " +count+" a keyvalue." );

            // Check if the dictionary contains the specified Key
            BOOLB=dic. ContainsKey ("xiaoming");

            // Check whether the dictionary contains the specified Value
            BOOLC = Dic. Containsvalue ( the);

            // try to get the Value corresponding to the specified key
            ints;
Dic. TryGetValue ("xiaoming", outs);

            // If the current dictionary contains xiaoming This key, then the corresponding Value is obtained and saved in the s in bb=true
            // If the current dictionary does not contain xiaoming This key, then s=null,bb= False


            // get Value by Key
            intage= dic["laowang"];
            Console. WriteLine (age);

        }
    }
}


Lan Unity Development Fundamentals Two--lesson 24 Dictionary

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.