嗚嗚喔學習筆記: C#-Dictionary

搜尋此網誌

2016年7月15日 星期五

C#-Dictionary

查表
using System;
using System.Collections;
using System.Collections.Generic;

/// <summary>
///     A simple indexer example.
/// </summary>
class ConsolePrint
{

    static void Main(string[] args)
    {
        Dictionary<string, string> dctNewWay =
        new Dictionary<string, string>()
        {
            {"Key1", "AAAA"}, {"Key2", "BBBB"},
            {"Key3", "CCCC"}, {"Key4", "DDDD"}
        };

        dctNewWay.Add("Key5", "EEEE");

        String FindByKey = dctNewWay["Key1"]; 
        bool AnyKey = dctNewWay.ContainsKey("key1");
        Console.WriteLine("FindByKey = {0}", FindByKey);
        Console.ReadLine();
    }
}

1 則留言: