Several traversal method C # Dictionary turn

  Dictionary<string, int> list = new Dictionary<string, int>();

 

            list.Add("d", 1);

 

            //3.0以上版本

            foreach (var item in list)

            {

                Console.WriteLine(item.Key + item.Value);

            }

            //KeyValuePair<T,K>

            foreach (KeyValuePair<string, int> kv in list)

            {

                Console.WriteLine (kv.Key + kv.Value); 

            } 

            // get a set of keys by 

            foreach ( String Key in list.Keys) 

            { 

                Console.WriteLine (Key + List [Key]); 

            } 

            // immediate value 

            foreach ( int Val in list.Values) 

            { 

                Console.WriteLine (Val); 

            } 

            // have to be employed for the methods 

            List < String > Test = new new List < String >(list.Keys);

 

            for (int i = 0; i < list.Count; i++)

            {

                Console.WriteLine(test[i] + list[test[i]]);

            }

Transfer from https://www.cnblogs.com/cjdxhc_site/articles/1727763.html

Guess you like

Origin www.cnblogs.com/enych/p/12233424.html