using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace learn_directory
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 定义
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            // 赋值方法
            dictionary["aaa"] = "aaa";
            dictionary.Add("bbb", "bbb");
            // 使用方法
            foreach (string key in dictionary.Keys)
            {
                Console.WriteLine(dictionary[key]);
            }
            foreach (string value in dictionary.Values)
            {
                Console.WriteLine(value);
            }
            foreach(KeyValuePair<string, string> pair in dictionary)
            {
                Console.WriteLine($"{pair.Key} => {pair.Value}");
            }



            Console.ReadKey();
        }
    }
}

执行结果

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace learn_directory
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 定义
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            // 赋值方法
            dictionary["aaa"] = "aaa";
            dictionary.Add("bbb", "bbb");
            // 使用方法
            foreach (string key in dictionary.Keys)
            {
                Console.WriteLine(dictionary[key]);
            }
            foreach (string value in dictionary.Values)
            {
                Console.WriteLine(value);
            }
            foreach(KeyValuePair<string, string> pair in dictionary)
            {
                Console.WriteLine($"{pair.Key} => {pair.Value}");
            }
            Console.ReadKey();
        }
    }
}
posted on 2023-01-22 23:38  盈盈的月儿  阅读(83)  评论(0编辑  收藏  举报