Dictionary<TKey, TValue> 的foreach便利方法

来源:互联网 发布:淘宝达人怎么发布内容 编辑:程序博客网 时间:2024/05/16 15:22
 

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

namespace MyTest
{
    class Program
    {
        public class myClass
        {
            Dictionary<string , string> dir = new Dictionary<string , string>();

            public myClass()
            {
                dir["aa"] = "xxxx";
                dir["bb"] = "eeee";
                dir["cc"] = "ffff";
                dir["dd"] = "sssss";
                dir["ee"] = "xggggxxx";
            }

            public Dictionary<string, string> Test()
            {
                return dir;
            }
        }


        static void Main(string[] args)
        {
            myClass class1 = new myClass();
            Dictionary<string,string> tt = class1.Test();
           
            foreach(KeyValuePair<string,string> pair in tt)
            {
                Console.WriteLine(pair.Key  + "……" + pair.Value);
            }
        }
    }
}

原创粉丝点击