Dictionary<string, List<string>> list = new Dictionary<string, List<string>>(); List<string> li=new List<string>(); li.Add("b"); li.Add("c"); list["a"]=li; foreach (string s in list["a"]) { Debug.WriteLine(s); } list["a"]就等于是一个list<string>类型 你也可以这样用 List<string> aList=list["a"];
using System; using System.Collections.Generic; namespace my { class myClass { static void Main() { List<string> persons = new List<string>(); for(int i = 0;i<10;i++) persons.Add("user"+i.ToString());
Dictionary<string,List<string>> DictionaryPerson = new Dictionary<string,List<string>>(); DictionaryPerson.Add("A",persons); List<string> items = DictionaryPerson["A"]; foreach(string item in items) Console.WriteLine("item:{0}",item); } } }
Dictionary<A, List<string>> list = new Dictionary<A, ListM<string>>();
A也是字符串,表示键按照你这样定义后,我想遍历某个键的值的集合呢怎么做呢?比如 list[A],这个键的值现在是一个集合,怎么遍历这个集合呀。
List<string> li=new List<string>();
li.Add("b");
li.Add("c");
list["a"]=li;
foreach (string s in list["a"])
{
Debug.WriteLine(s);
}
list["a"]就等于是一个list<string>类型
你也可以这样用
List<string> aList=list["a"];
using System;
using System.Collections.Generic;
namespace my
{
class myClass
{
static void Main()
{
List<string> persons = new List<string>();
for(int i = 0;i<10;i++)
persons.Add("user"+i.ToString());
Dictionary<string,List<string>> DictionaryPerson = new Dictionary<string,List<string>>();
DictionaryPerson.Add("A",persons);
List<string> items = DictionaryPerson["A"];
foreach(string item in items)
Console.WriteLine("item:{0}",item);
}
}
}